Change in openvpn[master]: allow tcp/udp server to listen on multiple ports at the same time
A message that is not in the archive (sent off-list or not yet received): gerrit.1700055887000.Ia0a889e800f0b36aed770ee36e31afeec5df6084@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
to review the following change.
Change subject: allow tcp/udp server to listen on multiple ports at the same time
......................................................................
allow tcp/udp server to listen on multiple ports at the same time
---
M src/openvpn/dco.c
M src/openvpn/event.h
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mss.c
M src/openvpn/mtcp.c
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/openvpn.c
M src/openvpn/openvpn.h
M src/openvpn/ovpn_dco_win.h
M src/openvpn/ping.h
M src/openvpn/socket.c
M src/openvpn/socket.h
18 files changed, 458 insertions(+), 231 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/34/434/1
src/openvpn/dco.c +7 -7
@@ -460,7 +460,7 @@return 0 ; } -struct link_socket *ls = c->c2.link_socket; +struct link_socket *ls = c->c2.link_sockets[0 ];ASSERT (ls->info.connection_established);
@@ -476,7 +476,7 @@ }#endif int ret =dco_new_peer (&c->c1.tuntap->dco, multi->peer_id, - c->c2.link_socket->sd,NULL , remoteaddr,NULL ,NULL ); + c->c2.link_sockets[0 ]->sd,NULL , remoteaddr,NULL ,NULL );if (ret <0 ) {return ret;
@@ -509,12 +509,12 @@#if ENABLE_IP_PKTINFO struct context *c = &mi->context; -if (!proto_is_udp (c->c2.link_socket->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) +if (!proto_is_udp (c->c2.link_sockets[0 ]->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) {return false; } -struct link_socket_actual *actual = &c->c2.link_socket_info->lsa->actual; +struct link_socket_actual *actual = &c->c2.link_socket_infos[0 ]->lsa->actual;switch (actual->dest.addr.sa.sa_family) {
@@ -559,7 +559,7 @@int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 }; -int sd = c->c2.link_socket->sd; +int sd = c->c2.link_sockets[0 ]->sd;if (c->mode ==CM_CHILD_TCP )
@@ -569,8 +569,8 @@ }else { -ASSERT (c->c2.link_socket_info->connection_established); - remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; +ASSERT (c->c2.link_socket_infos[0 ]->connection_established); + remoteaddr = &c->c2.link_socket_infos[0 ]->lsa->actual.dest.addr.sa; }/* In server mode we need to fetch the remote addresses from the push config */
src/openvpn/event.h +1 -0
@@ -141,6 +141,7 @@struct event_arg {event_arg_t type; +bool pending;/* in UDP/P2P mode marks sockets waiting for processing */ union {struct multi_instance *mi;/* if type = EVENT_ARG_MULTI_INSTANCE */ struct link_socket *ls;/* if type = EVENT_ARG_LINK_SOCKET */
src/openvpn/forward.c +35 -18
152 lines not on this page · raw message
src/openvpn/forward.h +14 -10
@@ -231,10 +231,12 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with the -* packet. +* @param c The context structure of the VPN tunnel associated with +* the packet. +* @param out_ls Socket that will be used to send out the packet. +* */ -void process_incoming_tun (struct context *c); +void process_incoming_tun (struct context *c,struct link_socket *out_ls);/**
@@ -246,10 +248,11 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with -* the packet. +* @param c The context structure of the VPN tunnel associated +* with the packet. +* @param in_ls Socket where the packet was received. */ -void process_outgoing_tun (struct context *c); +void process_outgoing_tun (struct context *c,struct link_socket *in_ls);/**************************************************************************/
@@ -303,20 +306,21 @@#define PIPV6_IMCP_NOHOST_CLIENT (1<<5)#define PIPV6_IMCP_NOHOST_SERVER (1<<6) -void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf); +void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf, +struct link_socket *ls);void schedule_exit (struct context *c,const int n_seconds,const int signal);static inline struct link_socket_info *get_link_socket_info (struct context *c) { -if (c->c2.link_socket_info) +if (c->c2.link_socket_infos) { -return c->c2.link_socket_info; +return c->c2.link_socket_infos[0 ]; }else { -return &c->c2.link_socket->info; +return &c->c2.link_sockets[0 ]->info; } }
src/openvpn/init.c +186 -69
448 lines not on this page · raw message
src/openvpn/init.h +2 -1
@@ -95,7 +95,8 @@bool do_deferred_options (struct context *c,const unsigned int found);void inherit_context_child (struct context *dest, -const struct context *src); +const struct context *src, +struct link_socket *ls);void inherit_context_top (struct context *dest,const struct context *src);
src/openvpn/mss.c +1 -1
@@ -357,7 +357,7 @@struct link_socket_info *lsi =get_link_socket_info (c);struct options *o = &c->options; -int pmtu = c->c2.link_socket->mtu; +int pmtu = c->c2.link_sockets[0 ]->mtu;sa_family_t af = lsi->lsa->actual.dest.addr.sa.sa_family;int proto = lsi->proto;
src/openvpn/mtcp.c +38 -24
129 lines not on this page · raw message
src/openvpn/mudp.c +17 -6
@@ -185,7 +185,8 @@*/ struct multi_instance * -multi_get_create_instance_udp (struct multi_context *m,bool *floated) +multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct mroute_addr real;
@@ -256,7 +257,7 @@* connect-freq but not against connect-freq-initial */ reflect_filter_rate_limit_decrease (m->initial_rate_limiter); - mi =multi_create_instance (m, &real); + mi =multi_create_instance (m, &real, ls);if (mi) {hash_add_fast (hash, bucket, &mi->real, hv, mi);
@@ -317,7 +318,7 @@msg_set_prefix ("Connection Attempt" ); m->top.c2.to_link = m->hmac_reply; m->top.c2.to_link_addr = m->hmac_reply_dest; -process_outgoing_link (&m->top, &m->top.c2.link_socket[0 ]); +process_outgoing_link (&m->top, m->top.c2.link_sockets[0 ]); m->hmac_reply_dest =NULL ; } }
@@ -380,10 +381,20 @@/* Incoming data on UDP port */ else if (status & SOCKET_READ) { -read_incoming_link (&m->top, m->top.c2.link_socket); -if (!IS_SIG (&m->top)) +int i; +for (i =0 ; i < m->top.c1.link_sockets_num; i++) { -multi_process_incoming_link (m,NULL , mpp_flags); +if (!m->top.c2.link_sockets[i]->ev_arg.pending) + { +continue ; + } + +read_incoming_link (&m->top, m->top.c2.link_sockets[i]); +if (!IS_SIG (&m->top)) + { +multi_process_incoming_link (m,NULL , mpp_flags, + m->top.c2.link_sockets[i]); + } } }/* Incoming data on TUN device */
src/openvpn/mudp.h +4 -2
@@ -55,12 +55,14 @@* it. If no entry exists, this function handles its creation, and if * successful, returns the newly created instance. * -* @param m - The single multi_context structure. +* @param m - The single multi_context structure. +* @param ls - Listening socket where this instance is connecting to * * @return A pointer to a multi_instance if one already existed for the * packet's source address or if one was a newly created successfully. * NULL if one did not yet exist and a new one was not created. */ -struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated); +struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls);#endif /* ifndef MUDP_H */
src/openvpn/multi.c +19 -11
@@ -682,7 +682,10 @@multi_client_disconnect_script (m, mi); } -close_context (&mi->context,SIGTERM ,CC_GC_FREE ); +if (mi->did_open_context) + { +close_context (&mi->context,SIGTERM ,CC_GC_FREE ); + }multi_tcp_instance_specific_free (mi);
@@ -750,7 +753,8 @@* Create a client instance object for a newly connected client. */ struct multi_instance * -multi_create_instance (struct multi_context *m,const struct mroute_addr *real) +multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct multi_instance *mi;
@@ -773,7 +777,8 @@generate_prefix (mi); } -inherit_context_child (&mi->context, &m->top); + mi->did_open_context = true; +inherit_context_child (&mi->context, &m->top, ls);if (IS_SIG (&mi->context)) { goto err;
@@ -3128,7 +3133,8 @@ }void -multi_process_float (struct multi_context *m,struct multi_instance *mi) +multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls) {struct mroute_addr real;struct hash *hash = m->hash;
@@ -3184,8 +3190,8 @@ mi->context.c2.to_link_addr = &mi->context.c2.from;/* inherit parent link_socket and link_socket_info */ - mi->context.c2.link_socket = m->top.c2.link_socket; - mi->context.c2.link_socket_info->lsa->actual = m->top.c2.from; + mi->context.c2.link_sockets[0 ] = ls; + mi->context.c2.link_socket_infos[0 ]->lsa->actual = m->top.c2.from;tls_update_remote_addr (mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3333,7 +3339,8 @@* i.e. client -> server direction. */ bool -multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags) +multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls) {struct gc_arena gc =gc_new ();
@@ -3354,7 +3361,7 @@#ifdef MULTI_DEBUG_EVENT_LOOP printf ("TCP/UDP -> TUN [%d]\n" ,BLEN (&m->top.c2.buf));#endif -multi_set_pending (m,multi_get_create_instance_udp (m, &floated)); +multi_set_pending (m,multi_get_create_instance_udp (m, &floated, ls)); }else {
@@ -3395,7 +3402,7 @@/* nonzero length means that we have a valid, decrypted packed */ if (floated && c->c2.buf.len >0 ) { -multi_process_float (m, m->pending); +multi_process_float (m, m->pending, ls); }process_incoming_link_part2 (c, lsi, orig_buf);
@@ -3614,7 +3621,7 @@ }/* encrypt in instance context */ -process_incoming_tun (c); +process_incoming_tun (c, c->c2.link_sockets[0 ]);/* postprocess and set wakeup */ ret =multi_process_post (m, m->pending, mpp_flags);
@@ -3646,7 +3653,8 @@ { pip_flags |=PIP_MSSFIX ; } -process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf); +process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf, + item.instance->context.c2.link_sockets[0 ]);encrypt_sign (&item.instance->context, true);mbuf_free_buf (item.buffer);
src/openvpn/multi.h +10 -5
@@ -125,6 +125,7 @@in_addr_t reporting_addr;/* IP address shown in status listing */ struct in6_addr reporting_addr_ipv6;/* IPv6 address in status listing */ +bool did_open_context;bool did_real_hash;bool did_iter;#ifdef ENABLE_MANAGEMENT
@@ -269,7 +270,8 @@void multi_top_free (struct multi_context *m); -struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real); +struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls);void multi_close_instance (struct multi_context *m,struct multi_instance *mi,bool shutdown);
@@ -283,7 +285,8 @@* existing peer. Updates multi_instance with new address, * updates hashtables in multi_context. */ -void multi_process_float (struct multi_context *m,struct multi_instance *mi); +void multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls);#define MPP_PRE_SELECT (1<<0)#define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -348,8 +351,10 @@* when using TCP transport. Otherwise NULL, as is * the case when using UDP transport. * @param mpp_flags - Fast I/O optimization flags. +* @param ls - Socket where the packet was received. */ -bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags); +bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls);/**
@@ -663,7 +668,7 @@#endif set_prefix (mi);vlan_process_outgoing_tun (m, mi); -process_outgoing_tun (&mi->context); +process_outgoing_tun (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
@@ -678,7 +683,7 @@ {bool ret = true;set_prefix (mi); -process_outgoing_link (&mi->context, mi->context.c2.link_socket); +process_outgoing_link (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
src/openvpn/openvpn.c +1 -1
@@ -89,7 +89,7 @@ }/* process the I/O which triggered select */ -process_io (c, c->c2.link_socket); +process_io (c, c->c2.link_sockets[0 ]);P2P_CHECK_SIG ();perf_pop ();
src/openvpn/openvpn.h +5 -4
@@ -154,7 +154,8 @@*/ struct context_1 { -struct link_socket_addr link_socket_addr; +int link_sockets_num; +struct link_socket_addr *link_socket_addrs;/**< Local and remote addresses on the * external network. */
@@ -237,11 +238,11 @@/* bitmask for event status. Check event.h for possible values */ unsigned int event_set_status; -struct link_socket *link_socket;/* socket used for TCP/UDP connection to remote */ +struct link_socket **link_sockets; +struct link_socket_info **link_socket_infos; +bool link_socket_owned; -/** This variable is used instead link_socket->info for P2MP UDP childs */ -struct link_socket_info *link_socket_info;const struct link_socket *accept_from;/* possibly do accept() on a parent link_socket */ struct link_socket_actual *to_link_addr;/* IP address of remote */
src/openvpn/ovpn_dco_win.h +1 -1
@@ -104,7 +104,7 @@LONG Major;LONG Minor;LONG Patch; -}OVPN_VERSION , *POVPN_VERSION ; +}OVPN_VERSION , *POVPN_VERSION ;#define OVPN_IOCTL_NEW_PEER CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_BUFFERED, FILE_ANY_ACCESS)#define OVPN_IOCTL_GET_STATS CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_BUFFERED, FILE_ANY_ACCESS)
src/openvpn/ping.h +1 -1
@@ -63,7 +63,7 @@ && event_timeout_trigger(&c->c2.ping_rec_interval, &c->c2.timeval, (!c->options.ping_timer_remote - || link_socket_actual_defined(&c->c1.link_socket_addr.actual)) + || link_socket_actual_defined(&c->c1.link_socket_addrs[0].actual)) ? ETT_DEFAULT : 15)) {trigger_ping_timeout_signal (c);
src/openvpn/socket.c +84 -63
261 lines not on this page · raw message
src/openvpn/socket.h +32 -7
@@ -329,9 +329,38 @@/* * Initialize link_socket object. */ -void link_socket_init_phase1 (struct context *c,int mode); +void +link_socket_init_phase1 (struct link_socket *sock, +const char *local_host, +const char *local_port, +const char *remote_host, +const char *remote_port, +struct cached_dns_entry *dns_cache, +int proto, +sa_family_t af, +bool bind_ipv6_only, +int mode, +const struct link_socket *accept_from, +struct http_proxy_info *http_proxy, +struct socks_proxy_info *socks_proxy, +#ifdef ENABLE_DEBUG + int gremlin, +#endif +bool bind_local, +bool remote_float, +struct link_socket_addr *lsa, +const char *ipchange_command, +const struct plugin_list *plugins, +int resolve_retry_seconds, +int mtu_discover_type, +int rcvbuf, +int sndbuf, +int mark, +struct event_timeout *server_poll_timeout, +unsigned int sockflags); -void link_socket_init_phase2 (struct context *c); +void link_socket_init_phase2 (struct context *c, +struct link_socket *sock);void do_preresolve (struct context *c);
@@ -1239,11 +1268,7 @@* Socket I/O wait functions */ -static inline bool -socket_read_residual (const struct link_socket *s) -{ -return s && s->stream_buf.residual_fully_formed; -} +bool sockets_read_residual (const struct context *c);static inline event_t socket_event_handle (const struct link_socket *s)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
ordex has abandoned this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: allow tcp/udp server to listen on multiple ports at the same time
......................................................................
Abandoned
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: abandon
ordex has restored this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: allow tcp/udp server to listen on multiple ports at the same time
......................................................................
Restored
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: restore
Attention is currently required from: flichtenheld, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: allow tcp/udp server to listen on multiple ports at the same time
......................................................................
Set Ready For Review
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 2
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 24 Sep 2024 20:43:00 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos.
its_Giaan has uploaded a new patch set (#3) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: allow tcp/udp server to listen on multiple ports at the same time
......................................................................
allow tcp/udp server to listen on multiple ports at the same time
---
M src/openvpn/dco.c
M src/openvpn/event.h
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mss.c
M src/openvpn/mtcp.c
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/openvpn.c
M src/openvpn/openvpn.h
M src/openvpn/ping.h
M src/openvpn/socket.c
M src/openvpn/socket.h
17 files changed, 462 insertions(+), 240 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/34/434/3
src/openvpn/dco.c +9 -9
@@ -479,11 +479,11 @@return 0 ; } -struct link_socket *ls = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[0 ]; -ASSERT (ls->info.connection_established); +ASSERT (sock->info.connection_established); -struct sockaddr *remoteaddr = &ls->info.lsa->actual.dest.addr.sa; +struct sockaddr *remoteaddr = &sock->info.lsa->actual.dest.addr.sa;struct tls_multi *multi = c->c2.tls_multi;#ifdef TARGET_FREEBSD /* In Linux in P2P mode the kernel automatically removes an existing peer
@@ -495,7 +495,7 @@ }#endif int ret =dco_new_peer (&c->c1.tuntap->dco, multi->peer_id, - c->c2.link_socket->sd,NULL , remoteaddr,NULL ,NULL ); + c->c2.link_sockets[0 ]->sd,NULL , remoteaddr,NULL ,NULL );if (ret <0 ) {return ret;
@@ -528,12 +528,12 @@#if ENABLE_IP_PKTINFO struct context *c = &mi->context; -if (!proto_is_udp (c->c2.link_socket->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) +if (!proto_is_udp (c->c2.link_sockets[0 ]->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) {return false; } -struct link_socket_actual *actual = &c->c2.link_socket_info->lsa->actual; +struct link_socket_actual *actual = &c->c2.link_socket_infos[0 ]->lsa->actual;switch (actual->dest.addr.sa.sa_family) {
@@ -578,7 +578,7 @@int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 }; -int sd = c->c2.link_socket->sd; +int sd = c->c2.link_sockets[0 ]->sd;if (c->mode ==CM_CHILD_TCP )
@@ -588,8 +588,8 @@ }else { -ASSERT (c->c2.link_socket_info->connection_established); - remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; +ASSERT (c->c2.link_socket_infos[0 ]->connection_established); + remoteaddr = &c->c2.link_socket_infos[0 ]->lsa->actual.dest.addr.sa; }/* In server mode we need to fetch the remote addresses from the push config */
src/openvpn/event.h +1 -0
@@ -141,6 +141,7 @@struct event_arg {event_arg_t type; +bool pending;/* in UDP/P2P mode marks sockets waiting for processing */ union {struct multi_instance *mi;/* if type = EVENT_ARG_MULTI_INSTANCE */ struct link_socket *sock;/* if type = EVENT_ARG_LINK_SOCKET */
src/openvpn/forward.c +35 -18
152 lines not on this page · raw message
src/openvpn/forward.h +14 -10
@@ -231,10 +231,12 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with the -* packet. +* @param c The context structure of the VPN tunnel associated with +* the packet. +* @param out_ls Socket that will be used to send out the packet. +* */ -void process_incoming_tun (struct context *c); +void process_incoming_tun (struct context *c,struct link_socket *out_ls);/**
@@ -246,10 +248,11 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with -* the packet. +* @param c The context structure of the VPN tunnel associated +* with the packet. +* @param in_ls Socket where the packet was received. */ -void process_outgoing_tun (struct context *c); +void process_outgoing_tun (struct context *c,struct link_socket *in_ls);/**************************************************************************/
@@ -304,20 +307,21 @@#define PIPV6_ICMP_NOHOST_SERVER (1<<6) -void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf); +void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf, +struct link_socket *ls);bool schedule_exit (struct context *c);static inline struct link_socket_info *get_link_socket_info (struct context *c) { -if (c->c2.link_socket_info) +if (c->c2.link_socket_infos) { -return c->c2.link_socket_info; +return c->c2.link_socket_infos[0 ]; }else { -return &c->c2.link_socket->info; +return &c->c2.link_sockets[0 ]->info; } }
src/openvpn/init.c +183 -74
448 lines not on this page · raw message
src/openvpn/init.h +2 -1
@@ -95,7 +95,8 @@bool do_deferred_options (struct context *c,const unsigned int found);void inherit_context_child (struct context *dest, -const struct context *src); +const struct context *src, +struct link_socket *ls);void inherit_context_top (struct context *dest,const struct context *src);
src/openvpn/mss.c +1 -1
@@ -357,7 +357,7 @@struct link_socket_info *lsi =get_link_socket_info (c);struct options *o = &c->options; -int pmtu = c->c2.link_socket->mtu; +int pmtu = c->c2.link_sockets[0 ]->mtu;sa_family_t af = lsi->lsa->actual.dest.addr.sa.sa_family;int proto = lsi->proto;
src/openvpn/mtcp.c +39 -24
135 lines not on this page · raw message
src/openvpn/mudp.c +17 -6
@@ -185,7 +185,8 @@*/ struct multi_instance * -multi_get_create_instance_udp (struct multi_context *m,bool *floated) +multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct mroute_addr real = {0 };
@@ -256,7 +257,7 @@* connect-freq but not against connect-freq-initial */ reflect_filter_rate_limit_decrease (m->initial_rate_limiter); - mi =multi_create_instance (m, &real); + mi =multi_create_instance (m, &real, ls);if (mi) {hash_add_fast (hash, bucket, &mi->real, hv, mi);
@@ -317,7 +318,7 @@msg_set_prefix ("Connection Attempt" ); m->top.c2.to_link = m->hmac_reply; m->top.c2.to_link_addr = m->hmac_reply_dest; -process_outgoing_link (&m->top, &m->top.c2.link_socket[0 ]); +process_outgoing_link (&m->top, m->top.c2.link_sockets[0 ]); m->hmac_reply_dest =NULL ; } }
@@ -380,10 +381,20 @@/* Incoming data on UDP port */ else if (status & SOCKET_READ) { -read_incoming_link (&m->top, m->top.c2.link_socket); -if (!IS_SIG (&m->top)) +int i; +for (i =0 ; i < m->top.c1.link_sockets_num; i++) { -multi_process_incoming_link (m,NULL , mpp_flags); +if (!m->top.c2.link_sockets[i]->ev_arg.pending) + { +continue ; + } + +read_incoming_link (&m->top, m->top.c2.link_sockets[i]); +if (!IS_SIG (&m->top)) + { +multi_process_incoming_link (m,NULL , mpp_flags, + m->top.c2.link_sockets[i]); + } } }/* Incoming data on TUN device */
src/openvpn/mudp.h +4 -2
@@ -55,12 +55,14 @@* it. If no entry exists, this function handles its creation, and if * successful, returns the newly created instance. * -* @param m - The single multi_context structure. +* @param m - The single multi_context structure. +* @param ls - Listening socket where this instance is connecting to * * @return A pointer to a multi_instance if one already existed for the * packet's source address or if one was a newly created successfully. * NULL if one did not yet exist and a new one was not created. */ -struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated); +struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls);#endif /* ifndef MUDP_H */
src/openvpn/multi.c +19 -11
@@ -682,7 +682,10 @@multi_client_disconnect_script (m, mi); } -close_context (&mi->context,SIGTERM ,CC_GC_FREE ); +if (mi->did_open_context) + { +close_context (&mi->context,SIGTERM ,CC_GC_FREE ); + }multi_tcp_instance_specific_free (mi);
@@ -750,7 +753,8 @@* Create a client instance object for a newly connected client. */ struct multi_instance * -multi_create_instance (struct multi_context *m,const struct mroute_addr *real) +multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct multi_instance *mi;
@@ -773,7 +777,8 @@generate_prefix (mi); } -inherit_context_child (&mi->context, &m->top); + mi->did_open_context = true; +inherit_context_child (&mi->context, &m->top, ls);if (IS_SIG (&mi->context)) { goto err;
@@ -3124,7 +3129,8 @@ }void -multi_process_float (struct multi_context *m,struct multi_instance *mi) +multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls) {struct mroute_addr real = {0 };struct hash *hash = m->hash;
@@ -3180,8 +3186,8 @@ mi->context.c2.to_link_addr = &mi->context.c2.from;/* inherit parent link_socket and link_socket_info */ - mi->context.c2.link_socket = m->top.c2.link_socket; - mi->context.c2.link_socket_info->lsa->actual = m->top.c2.from; + mi->context.c2.link_sockets[0 ] = ls; + mi->context.c2.link_socket_infos[0 ]->lsa->actual = m->top.c2.from;tls_update_remote_addr (mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3329,7 +3335,8 @@* i.e. client -> server direction. */ bool -multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags) +multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls) {struct gc_arena gc =gc_new ();
@@ -3350,7 +3357,7 @@#ifdef MULTI_DEBUG_EVENT_LOOP printf ("TCP/UDP -> TUN [%d]\n" ,BLEN (&m->top.c2.buf));#endif -multi_set_pending (m,multi_get_create_instance_udp (m, &floated)); +multi_set_pending (m,multi_get_create_instance_udp (m, &floated, ls)); }else {
@@ -3391,7 +3398,7 @@/* nonzero length means that we have a valid, decrypted packed */ if (floated && c->c2.buf.len >0 ) { -multi_process_float (m, m->pending); +multi_process_float (m, m->pending, ls); }process_incoming_link_part2 (c, lsi, orig_buf);
@@ -3610,7 +3617,7 @@ }/* encrypt in instance context */ -process_incoming_tun (c); +process_incoming_tun (c, c->c2.link_sockets[0 ]);/* postprocess and set wakeup */ ret =multi_process_post (m, m->pending, mpp_flags);
@@ -3642,7 +3649,8 @@ { pip_flags |=PIP_MSSFIX ; } -process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf); +process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf, + item.instance->context.c2.link_sockets[0 ]);encrypt_sign (&item.instance->context, true);mbuf_free_buf (item.buffer);
src/openvpn/multi.h +10 -5
@@ -130,6 +130,7 @@in_addr_t reporting_addr;/* IP address shown in status listing */ struct in6_addr reporting_addr_ipv6;/* IPv6 address in status listing */ +bool did_open_context;bool did_real_hash;bool did_iter;#ifdef ENABLE_MANAGEMENT
@@ -274,7 +275,8 @@void multi_top_free (struct multi_context *m); -struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real); +struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls);void multi_close_instance (struct multi_context *m,struct multi_instance *mi,bool shutdown);
@@ -288,7 +290,8 @@* existing peer. Updates multi_instance with new address, * updates hashtables in multi_context. */ -void multi_process_float (struct multi_context *m,struct multi_instance *mi); +void multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls);#define MPP_PRE_SELECT (1<<0)#define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -353,8 +356,10 @@* when using TCP transport. Otherwise NULL, as is * the case when using UDP transport. * @param mpp_flags - Fast I/O optimization flags. +* @param ls - Socket where the packet was received. */ -bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags); +bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls);/**
@@ -668,7 +673,7 @@#endif set_prefix (mi);vlan_process_outgoing_tun (m, mi); -process_outgoing_tun (&mi->context); +process_outgoing_tun (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
@@ -683,7 +688,7 @@ {bool ret = true;set_prefix (mi); -process_outgoing_link (&mi->context, mi->context.c2.link_socket); +process_outgoing_link (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
src/openvpn/openvpn.c +1 -1
@@ -91,7 +91,7 @@ }/* process the I/O which triggered select */ -process_io (c, c->c2.link_socket); +process_io (c, c->c2.link_sockets[0 ]);P2P_CHECK_SIG ();perf_pop ();
src/openvpn/openvpn.h +5 -4
@@ -154,7 +154,8 @@*/ struct context_1 { -struct link_socket_addr link_socket_addr; +int link_sockets_num; +struct link_socket_addr *link_socket_addrs;/**< Local and remote addresses on the * external network. */
@@ -237,11 +238,11 @@/* bitmask for event status. Check event.h for possible values */ unsigned int event_set_status; -struct link_socket *link_socket;/* socket used for TCP/UDP connection to remote */ +struct link_socket **link_sockets; +struct link_socket_info **link_socket_infos; +bool link_socket_owned; -/** This variable is used instead link_socket->info for P2MP UDP childs */ -struct link_socket_info *link_socket_info;const struct link_socket *accept_from;/* possibly do accept() on a parent link_socket */ struct link_socket_actual *to_link_addr;/* IP address of remote */
src/openvpn/ping.h +1 -1
@@ -63,7 +63,7 @@ && event_timeout_trigger(&c->c2.ping_rec_interval, &c->c2.timeval, (!c->options.ping_timer_remote - || link_socket_actual_defined(&c->c1.link_socket_addr.actual)) + || link_socket_actual_defined(&c->c1.link_socket_addrs[0].actual)) ? ETT_DEFAULT : 15)) {trigger_ping_timeout_signal (c);
src/openvpn/socket.c +87 -66
268 lines not on this page · raw message
src/openvpn/socket.h +34 -7
54 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 3
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
its_Giaan has uploaded a new patch set (#4) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: allow tcp/udp server to listen on multiple ports at the same time
......................................................................
allow tcp/udp server to listen on multiple ports at the same time
---
M src/openvpn/dco.c
M src/openvpn/event.h
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mss.c
M src/openvpn/mtcp.c
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/openvpn.c
M src/openvpn/openvpn.h
M src/openvpn/ping.h
M src/openvpn/socket.c
M src/openvpn/socket.h
17 files changed, 458 insertions(+), 236 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/34/434/4
src/openvpn/dco.c +9 -9
@@ -479,11 +479,11 @@return 0 ; } -struct link_socket *ls = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[0 ]; -ASSERT (ls->info.connection_established); +ASSERT (sock->info.connection_established); -struct sockaddr *remoteaddr = &ls->info.lsa->actual.dest.addr.sa; +struct sockaddr *remoteaddr = &sock->info.lsa->actual.dest.addr.sa;struct tls_multi *multi = c->c2.tls_multi;#ifdef TARGET_FREEBSD /* In Linux in P2P mode the kernel automatically removes an existing peer
@@ -495,7 +495,7 @@ }#endif int ret =dco_new_peer (&c->c1.tuntap->dco, multi->peer_id, - c->c2.link_socket->sd,NULL , remoteaddr,NULL ,NULL ); + c->c2.link_sockets[0 ]->sd,NULL , remoteaddr,NULL ,NULL );if (ret <0 ) {return ret;
@@ -528,12 +528,12 @@#if ENABLE_IP_PKTINFO struct context *c = &mi->context; -if (!proto_is_udp (c->c2.link_socket->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) +if (!proto_is_udp (c->c2.link_sockets[0 ]->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) {return false; } -struct link_socket_actual *actual = &c->c2.link_socket_info->lsa->actual; +struct link_socket_actual *actual = &c->c2.link_socket_infos[0 ]->lsa->actual;switch (actual->dest.addr.sa.sa_family) {
@@ -578,7 +578,7 @@int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 }; -int sd = c->c2.link_socket->sd; +int sd = c->c2.link_sockets[0 ]->sd;if (c->mode ==CM_CHILD_TCP )
@@ -588,8 +588,8 @@ }else { -ASSERT (c->c2.link_socket_info->connection_established); - remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; +ASSERT (c->c2.link_socket_infos[0 ]->connection_established); + remoteaddr = &c->c2.link_socket_infos[0 ]->lsa->actual.dest.addr.sa; }/* In server mode we need to fetch the remote addresses from the push config */
src/openvpn/event.h +1 -0
@@ -141,6 +141,7 @@struct event_arg {event_arg_t type; +bool pending;/* in UDP/P2P mode marks sockets waiting for processing */ union {struct multi_instance *mi;/* if type = EVENT_ARG_MULTI_INSTANCE */ struct link_socket *sock;/* if type = EVENT_ARG_LINK_SOCKET */
src/openvpn/forward.c +35 -18
152 lines not on this page · raw message
src/openvpn/forward.h +14 -10
@@ -231,10 +231,12 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with the -* packet. +* @param c The context structure of the VPN tunnel associated with +* the packet. +* @param out_ls Socket that will be used to send out the packet. +* */ -void process_incoming_tun (struct context *c); +void process_incoming_tun (struct context *c,struct link_socket *out_ls);/**
@@ -246,10 +248,11 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with -* the packet. +* @param c The context structure of the VPN tunnel associated +* with the packet. +* @param in_ls Socket where the packet was received. */ -void process_outgoing_tun (struct context *c); +void process_outgoing_tun (struct context *c,struct link_socket *in_ls);/**************************************************************************/
@@ -304,20 +307,21 @@#define PIPV6_ICMP_NOHOST_SERVER (1<<6) -void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf); +void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf, +struct link_socket *ls);bool schedule_exit (struct context *c);static inline struct link_socket_info *get_link_socket_info (struct context *c) { -if (c->c2.link_socket_info) +if (c->c2.link_socket_infos) { -return c->c2.link_socket_info; +return c->c2.link_socket_infos[0 ]; }else { -return &c->c2.link_socket->info; +return &c->c2.link_sockets[0 ]->info; } }
src/openvpn/init.c +183 -74
448 lines not on this page · raw message
src/openvpn/init.h +2 -1
@@ -95,7 +95,8 @@bool do_deferred_options (struct context *c,const unsigned int found);void inherit_context_child (struct context *dest, -const struct context *src); +const struct context *src, +struct link_socket *ls);void inherit_context_top (struct context *dest,const struct context *src);
src/openvpn/mss.c +1 -1
@@ -357,7 +357,7 @@struct link_socket_info *lsi =get_link_socket_info (c);struct options *o = &c->options; -int pmtu = c->c2.link_socket->mtu; +int pmtu = c->c2.link_sockets[0 ]->mtu;sa_family_t af = lsi->lsa->actual.dest.addr.sa.sa_family;int proto = lsi->proto;
src/openvpn/mtcp.c +36 -21
123 lines not on this page · raw message
src/openvpn/mudp.c +16 -5
@@ -185,7 +185,8 @@*/ struct multi_instance * -multi_get_create_instance_udp (struct multi_context *m,bool *floated) +multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct mroute_addr real = {0 };
@@ -256,7 +257,7 @@* connect-freq but not against connect-freq-initial */ reflect_filter_rate_limit_decrease (m->initial_rate_limiter); - mi =multi_create_instance (m, &real); + mi =multi_create_instance (m, &real, ls);if (mi) {hash_add_fast (hash, bucket, &mi->real, hv, mi);
@@ -380,10 +381,20 @@/* Incoming data on UDP port */ else if (status & SOCKET_READ) { -read_incoming_link (&m->top, m->top.c2.link_socket); -if (!IS_SIG (&m->top)) +int i; +for (i =0 ; i < m->top.c1.link_sockets_num; i++) { -multi_process_incoming_link (m,NULL , mpp_flags); +if (!m->top.c2.link_sockets[i]->ev_arg.pending) + { +continue ; + } + +read_incoming_link (&m->top, m->top.c2.link_sockets[i]); +if (!IS_SIG (&m->top)) + { +multi_process_incoming_link (m,NULL , mpp_flags, + m->top.c2.link_sockets[i]); + } } }/* Incoming data on TUN device */
src/openvpn/mudp.h +4 -2
@@ -55,12 +55,14 @@* it. If no entry exists, this function handles its creation, and if * successful, returns the newly created instance. * -* @param m - The single multi_context structure. +* @param m - The single multi_context structure. +* @param ls - Listening socket where this instance is connecting to * * @return A pointer to a multi_instance if one already existed for the * packet's source address or if one was a newly created successfully. * NULL if one did not yet exist and a new one was not created. */ -struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated); +struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls);#endif /* ifndef MUDP_H */
src/openvpn/multi.c +19 -11
@@ -682,7 +682,10 @@multi_client_disconnect_script (m, mi); } -close_context (&mi->context,SIGTERM ,CC_GC_FREE ); +if (mi->did_open_context) + { +close_context (&mi->context,SIGTERM ,CC_GC_FREE ); + }multi_tcp_instance_specific_free (mi);
@@ -750,7 +753,8 @@* Create a client instance object for a newly connected client. */ struct multi_instance * -multi_create_instance (struct multi_context *m,const struct mroute_addr *real) +multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct multi_instance *mi;
@@ -773,7 +777,8 @@generate_prefix (mi); } -inherit_context_child (&mi->context, &m->top); + mi->did_open_context = true; +inherit_context_child (&mi->context, &m->top, ls);if (IS_SIG (&mi->context)) { goto err;
@@ -3124,7 +3129,8 @@ }void -multi_process_float (struct multi_context *m,struct multi_instance *mi) +multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls) {struct mroute_addr real = {0 };struct hash *hash = m->hash;
@@ -3180,8 +3186,8 @@ mi->context.c2.to_link_addr = &mi->context.c2.from;/* inherit parent link_socket and link_socket_info */ - mi->context.c2.link_socket = m->top.c2.link_socket; - mi->context.c2.link_socket_info->lsa->actual = m->top.c2.from; + mi->context.c2.link_sockets[0 ] = ls; + mi->context.c2.link_socket_infos[0 ]->lsa->actual = m->top.c2.from;tls_update_remote_addr (mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3329,7 +3335,8 @@* i.e. client -> server direction. */ bool -multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags) +multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls) {struct gc_arena gc =gc_new ();
@@ -3350,7 +3357,7 @@#ifdef MULTI_DEBUG_EVENT_LOOP printf ("TCP/UDP -> TUN [%d]\n" ,BLEN (&m->top.c2.buf));#endif -multi_set_pending (m,multi_get_create_instance_udp (m, &floated)); +multi_set_pending (m,multi_get_create_instance_udp (m, &floated, ls)); }else {
@@ -3391,7 +3398,7 @@/* nonzero length means that we have a valid, decrypted packed */ if (floated && c->c2.buf.len >0 ) { -multi_process_float (m, m->pending); +multi_process_float (m, m->pending, ls); }process_incoming_link_part2 (c, lsi, orig_buf);
@@ -3610,7 +3617,7 @@ }/* encrypt in instance context */ -process_incoming_tun (c); +process_incoming_tun (c, c->c2.link_sockets[0 ]);/* postprocess and set wakeup */ ret =multi_process_post (m, m->pending, mpp_flags);
@@ -3642,7 +3649,8 @@ { pip_flags |=PIP_MSSFIX ; } -process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf); +process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf, + item.instance->context.c2.link_sockets[0 ]);encrypt_sign (&item.instance->context, true);mbuf_free_buf (item.buffer);
src/openvpn/multi.h +10 -5
@@ -130,6 +130,7 @@in_addr_t reporting_addr;/* IP address shown in status listing */ struct in6_addr reporting_addr_ipv6;/* IPv6 address in status listing */ +bool did_open_context;bool did_real_hash;bool did_iter;#ifdef ENABLE_MANAGEMENT
@@ -274,7 +275,8 @@void multi_top_free (struct multi_context *m); -struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real); +struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls);void multi_close_instance (struct multi_context *m,struct multi_instance *mi,bool shutdown);
@@ -288,7 +290,8 @@* existing peer. Updates multi_instance with new address, * updates hashtables in multi_context. */ -void multi_process_float (struct multi_context *m,struct multi_instance *mi); +void multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls);#define MPP_PRE_SELECT (1<<0)#define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -353,8 +356,10 @@* when using TCP transport. Otherwise NULL, as is * the case when using UDP transport. * @param mpp_flags - Fast I/O optimization flags. +* @param ls - Socket where the packet was received. */ -bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags); +bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls);/**
@@ -668,7 +673,7 @@#endif set_prefix (mi);vlan_process_outgoing_tun (m, mi); -process_outgoing_tun (&mi->context); +process_outgoing_tun (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
@@ -683,7 +688,7 @@ {bool ret = true;set_prefix (mi); -process_outgoing_link (&mi->context, mi->context.c2.link_socket); +process_outgoing_link (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
src/openvpn/openvpn.c +1 -1
@@ -91,7 +91,7 @@ }/* process the I/O which triggered select */ -process_io (c, c->c2.link_socket); +process_io (c, c->c2.link_sockets[0 ]);P2P_CHECK_SIG ();perf_pop ();
src/openvpn/openvpn.h +5 -4
@@ -154,7 +154,8 @@*/ struct context_1 { -struct link_socket_addr link_socket_addr; +int link_sockets_num; +struct link_socket_addr *link_socket_addrs;/**< Local and remote addresses on the * external network. */
@@ -237,11 +238,11 @@/* bitmask for event status. Check event.h for possible values */ unsigned int event_set_status; -struct link_socket *link_socket;/* socket used for TCP/UDP connection to remote */ +struct link_socket **link_sockets; +struct link_socket_info **link_socket_infos; +bool link_socket_owned; -/** This variable is used instead link_socket->info for P2MP UDP childs */ -struct link_socket_info *link_socket_info;const struct link_socket *accept_from;/* possibly do accept() on a parent link_socket */ struct link_socket_actual *to_link_addr;/* IP address of remote */
src/openvpn/ping.h +1 -1
@@ -63,7 +63,7 @@ && event_timeout_trigger(&c->c2.ping_rec_interval, &c->c2.timeval, (!c->options.ping_timer_remote - || link_socket_actual_defined(&c->c1.link_socket_addr.actual)) + || link_socket_actual_defined(&c->c1.link_socket_addrs[0].actual)) ? ETT_DEFAULT : 15)) {trigger_ping_timeout_signal (c);
src/openvpn/socket.c +87 -66
268 lines not on this page · raw message
src/openvpn/socket.h +34 -7
54 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 4
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: its_Giaan, ordex, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: allow tcp/udp server to listen on multiple ports at the same time
......................................................................
Patch Set 4: Code-Review-2
(1 comment)
Patchset:
PS4:
build broken
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 4
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 09 Oct 2024 10:21:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: its_Giaan, ordex, plaisthos.
its_Giaan has uploaded a new patch set (#5) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: allow tcp/udp server to listen on multiple ports at the same time
......................................................................
allow tcp/udp server to listen on multiple ports at the same time
---
M src/openvpn/dco.c
M src/openvpn/event.h
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mss.c
M src/openvpn/mtcp.c
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/openvpn.c
M src/openvpn/openvpn.h
M src/openvpn/ping.h
M src/openvpn/socket.c
M src/openvpn/socket.h
17 files changed, 459 insertions(+), 237 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/34/434/5
src/openvpn/dco.c +9 -9
@@ -479,11 +479,11 @@return 0 ; } -struct link_socket *ls = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[0 ]; -ASSERT (ls->info.connection_established); +ASSERT (sock->info.connection_established); -struct sockaddr *remoteaddr = &ls->info.lsa->actual.dest.addr.sa; +struct sockaddr *remoteaddr = &sock->info.lsa->actual.dest.addr.sa;struct tls_multi *multi = c->c2.tls_multi;#ifdef TARGET_FREEBSD /* In Linux in P2P mode the kernel automatically removes an existing peer
@@ -495,7 +495,7 @@ }#endif int ret =dco_new_peer (&c->c1.tuntap->dco, multi->peer_id, - c->c2.link_socket->sd,NULL , remoteaddr,NULL ,NULL ); + c->c2.link_sockets[0 ]->sd,NULL , remoteaddr,NULL ,NULL );if (ret <0 ) {return ret;
@@ -528,12 +528,12 @@#if ENABLE_IP_PKTINFO struct context *c = &mi->context; -if (!proto_is_udp (c->c2.link_socket->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) +if (!proto_is_udp (c->c2.link_sockets[0 ]->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) {return false; } -struct link_socket_actual *actual = &c->c2.link_socket_info->lsa->actual; +struct link_socket_actual *actual = &c->c2.link_socket_infos[0 ]->lsa->actual;switch (actual->dest.addr.sa.sa_family) {
@@ -578,7 +578,7 @@int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 }; -int sd = c->c2.link_socket->sd; +int sd = c->c2.link_sockets[0 ]->sd;if (c->mode ==CM_CHILD_TCP )
@@ -588,8 +588,8 @@ }else { -ASSERT (c->c2.link_socket_info->connection_established); - remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; +ASSERT (c->c2.link_socket_infos[0 ]->connection_established); + remoteaddr = &c->c2.link_socket_infos[0 ]->lsa->actual.dest.addr.sa; }/* In server mode we need to fetch the remote addresses from the push config */
src/openvpn/event.h +1 -0
@@ -141,6 +141,7 @@struct event_arg {event_arg_t type; +bool pending;/* in UDP/P2P mode marks sockets waiting for processing */ union {struct multi_instance *mi;/* if type = EVENT_ARG_MULTI_INSTANCE */ struct link_socket *sock;/* if type = EVENT_ARG_LINK_SOCKET */
src/openvpn/forward.c +35 -18
152 lines not on this page · raw message
src/openvpn/forward.h +14 -10
@@ -231,10 +231,12 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with the -* packet. +* @param c The context structure of the VPN tunnel associated with +* the packet. +* @param out_ls Socket that will be used to send out the packet. +* */ -void process_incoming_tun (struct context *c); +void process_incoming_tun (struct context *c,struct link_socket *out_ls);/**
@@ -246,10 +248,11 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with -* the packet. +* @param c The context structure of the VPN tunnel associated +* with the packet. +* @param in_ls Socket where the packet was received. */ -void process_outgoing_tun (struct context *c); +void process_outgoing_tun (struct context *c,struct link_socket *in_ls);/**************************************************************************/
@@ -304,20 +307,21 @@#define PIPV6_ICMP_NOHOST_SERVER (1<<6) -void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf); +void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf, +struct link_socket *ls);bool schedule_exit (struct context *c);static inline struct link_socket_info *get_link_socket_info (struct context *c) { -if (c->c2.link_socket_info) +if (c->c2.link_socket_infos) { -return c->c2.link_socket_info; +return c->c2.link_socket_infos[0 ]; }else { -return &c->c2.link_socket->info; +return &c->c2.link_sockets[0 ]->info; } }
src/openvpn/init.c +183 -74
448 lines not on this page · raw message
src/openvpn/init.h +2 -1
@@ -95,7 +95,8 @@bool do_deferred_options (struct context *c,const unsigned int found);void inherit_context_child (struct context *dest, -const struct context *src); +const struct context *src, +struct link_socket *ls);void inherit_context_top (struct context *dest,const struct context *src);
src/openvpn/mss.c +1 -1
@@ -357,7 +357,7 @@struct link_socket_info *lsi =get_link_socket_info (c);struct options *o = &c->options; -int pmtu = c->c2.link_socket->mtu; +int pmtu = c->c2.link_sockets[0 ]->mtu;sa_family_t af = lsi->lsa->actual.dest.addr.sa.sa_family;int proto = lsi->proto;
src/openvpn/mtcp.c +36 -21
123 lines not on this page · raw message
src/openvpn/mudp.c +17 -6
@@ -185,7 +185,8 @@*/ struct multi_instance * -multi_get_create_instance_udp (struct multi_context *m,bool *floated) +multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct mroute_addr real = {0 };
@@ -256,7 +257,7 @@* connect-freq but not against connect-freq-initial */ reflect_filter_rate_limit_decrease (m->initial_rate_limiter); - mi =multi_create_instance (m, &real); + mi =multi_create_instance (m, &real, ls);if (mi) {hash_add_fast (hash, bucket, &mi->real, hv, mi);
@@ -317,7 +318,7 @@msg_set_prefix ("Connection Attempt" ); m->top.c2.to_link = m->hmac_reply; m->top.c2.to_link_addr = m->hmac_reply_dest; -process_outgoing_link (&m->top, m->top.c2.link_socket); +process_outgoing_link (&m->top, m->top.c2.link_sockets[0 ]); m->hmac_reply_dest =NULL ; } }
@@ -380,10 +381,20 @@/* Incoming data on UDP port */ else if (status & SOCKET_READ) { -read_incoming_link (&m->top, m->top.c2.link_socket); -if (!IS_SIG (&m->top)) +int i; +for (i =0 ; i < m->top.c1.link_sockets_num; i++) { -multi_process_incoming_link (m,NULL , mpp_flags); +if (!m->top.c2.link_sockets[i]->ev_arg.pending) + { +continue ; + } + +read_incoming_link (&m->top, m->top.c2.link_sockets[i]); +if (!IS_SIG (&m->top)) + { +multi_process_incoming_link (m,NULL , mpp_flags, + m->top.c2.link_sockets[i]); + } } }/* Incoming data on TUN device */
src/openvpn/mudp.h +4 -2
@@ -55,12 +55,14 @@* it. If no entry exists, this function handles its creation, and if * successful, returns the newly created instance. * -* @param m - The single multi_context structure. +* @param m - The single multi_context structure. +* @param ls - Listening socket where this instance is connecting to * * @return A pointer to a multi_instance if one already existed for the * packet's source address or if one was a newly created successfully. * NULL if one did not yet exist and a new one was not created. */ -struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated); +struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls);#endif /* ifndef MUDP_H */
src/openvpn/multi.c +19 -11
@@ -682,7 +682,10 @@multi_client_disconnect_script (m, mi); } -close_context (&mi->context,SIGTERM ,CC_GC_FREE ); +if (mi->did_open_context) + { +close_context (&mi->context,SIGTERM ,CC_GC_FREE ); + }multi_tcp_instance_specific_free (mi);
@@ -750,7 +753,8 @@* Create a client instance object for a newly connected client. */ struct multi_instance * -multi_create_instance (struct multi_context *m,const struct mroute_addr *real) +multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct multi_instance *mi;
@@ -773,7 +777,8 @@generate_prefix (mi); } -inherit_context_child (&mi->context, &m->top); + mi->did_open_context = true; +inherit_context_child (&mi->context, &m->top, ls);if (IS_SIG (&mi->context)) { goto err;
@@ -3124,7 +3129,8 @@ }void -multi_process_float (struct multi_context *m,struct multi_instance *mi) +multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls) {struct mroute_addr real = {0 };struct hash *hash = m->hash;
@@ -3180,8 +3186,8 @@ mi->context.c2.to_link_addr = &mi->context.c2.from;/* inherit parent link_socket and link_socket_info */ - mi->context.c2.link_socket = m->top.c2.link_socket; - mi->context.c2.link_socket_info->lsa->actual = m->top.c2.from; + mi->context.c2.link_sockets[0 ] = ls; + mi->context.c2.link_socket_infos[0 ]->lsa->actual = m->top.c2.from;tls_update_remote_addr (mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3329,7 +3335,8 @@* i.e. client -> server direction. */ bool -multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags) +multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls) {struct gc_arena gc =gc_new ();
@@ -3350,7 +3357,7 @@#ifdef MULTI_DEBUG_EVENT_LOOP printf ("TCP/UDP -> TUN [%d]\n" ,BLEN (&m->top.c2.buf));#endif -multi_set_pending (m,multi_get_create_instance_udp (m, &floated)); +multi_set_pending (m,multi_get_create_instance_udp (m, &floated, ls)); }else {
@@ -3391,7 +3398,7 @@/* nonzero length means that we have a valid, decrypted packed */ if (floated && c->c2.buf.len >0 ) { -multi_process_float (m, m->pending); +multi_process_float (m, m->pending, ls); }process_incoming_link_part2 (c, lsi, orig_buf);
@@ -3610,7 +3617,7 @@ }/* encrypt in instance context */ -process_incoming_tun (c); +process_incoming_tun (c, c->c2.link_sockets[0 ]);/* postprocess and set wakeup */ ret =multi_process_post (m, m->pending, mpp_flags);
@@ -3642,7 +3649,8 @@ { pip_flags |=PIP_MSSFIX ; } -process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf); +process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf, + item.instance->context.c2.link_sockets[0 ]);encrypt_sign (&item.instance->context, true);mbuf_free_buf (item.buffer);
src/openvpn/multi.h +10 -5
@@ -130,6 +130,7 @@in_addr_t reporting_addr;/* IP address shown in status listing */ struct in6_addr reporting_addr_ipv6;/* IPv6 address in status listing */ +bool did_open_context;bool did_real_hash;bool did_iter;#ifdef ENABLE_MANAGEMENT
@@ -274,7 +275,8 @@void multi_top_free (struct multi_context *m); -struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real); +struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls);void multi_close_instance (struct multi_context *m,struct multi_instance *mi,bool shutdown);
@@ -288,7 +290,8 @@* existing peer. Updates multi_instance with new address, * updates hashtables in multi_context. */ -void multi_process_float (struct multi_context *m,struct multi_instance *mi); +void multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls);#define MPP_PRE_SELECT (1<<0)#define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -353,8 +356,10 @@* when using TCP transport. Otherwise NULL, as is * the case when using UDP transport. * @param mpp_flags - Fast I/O optimization flags. +* @param ls - Socket where the packet was received. */ -bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags); +bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls);/**
@@ -668,7 +673,7 @@#endif set_prefix (mi);vlan_process_outgoing_tun (m, mi); -process_outgoing_tun (&mi->context); +process_outgoing_tun (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
@@ -683,7 +688,7 @@ {bool ret = true;set_prefix (mi); -process_outgoing_link (&mi->context, mi->context.c2.link_socket); +process_outgoing_link (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
src/openvpn/openvpn.c +1 -1
@@ -91,7 +91,7 @@ }/* process the I/O which triggered select */ -process_io (c, c->c2.link_socket); +process_io (c, c->c2.link_sockets[0 ]);P2P_CHECK_SIG ();perf_pop ();
src/openvpn/openvpn.h +5 -4
@@ -154,7 +154,8 @@*/ struct context_1 { -struct link_socket_addr link_socket_addr; +int link_sockets_num; +struct link_socket_addr *link_socket_addrs;/**< Local and remote addresses on the * external network. */
@@ -237,11 +238,11 @@/* bitmask for event status. Check event.h for possible values */ unsigned int event_set_status; -struct link_socket *link_socket;/* socket used for TCP/UDP connection to remote */ +struct link_socket **link_sockets; +struct link_socket_info **link_socket_infos; +bool link_socket_owned; -/** This variable is used instead link_socket->info for P2MP UDP childs */ -struct link_socket_info *link_socket_info;const struct link_socket *accept_from;/* possibly do accept() on a parent link_socket */ struct link_socket_actual *to_link_addr;/* IP address of remote */
src/openvpn/ping.h +1 -1
@@ -63,7 +63,7 @@ && event_timeout_trigger(&c->c2.ping_rec_interval, &c->c2.timeval, (!c->options.ping_timer_remote - || link_socket_actual_defined(&c->c1.link_socket_addr.actual)) + || link_socket_actual_defined(&c->c1.link_socket_addrs[0].actual)) ? ETT_DEFAULT : 15)) {trigger_ping_timeout_signal (c);
src/openvpn/socket.c +87 -66
268 lines not on this page · raw message
src/openvpn/socket.h +34 -7
54 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 5
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: its_Giaan, ordex, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: allow tcp/udp server to listen on multiple ports at the same time
......................................................................
Patch Set 5: Code-Review-2
(19 comments)
Commit Message:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/d86891df_56a16db7 :
PS5, Line 7: allow tcp/udp server to listen on multiple ports at the same time
For a change this fundamental this commit message is not enough.
At least it should answer whether this actually changes any default behavior? Is there a way to use this functionality with only this patch?
Patchset:
PS5:
Could definitely use
- a cleanup of old code styles
- some more commit message
- some more doxygen documentation
- a discussion about alternatives to 25 parameters to a function
File src/openvpn/forward.h:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/43fc1b4c_0009fdae :
PS5, Line 239: void process_incoming_tun(struct context *c, struct link_socket *out_ls); I think we have implicitly agreed to call those out_sock?
http://gerrit.openvpn.net/c/openvpn/+/434/comment/e3e073d2_b0854f7c :
PS5, Line 311: struct link_socket *ls);
let's stick with sock to be consistent?
File src/openvpn/forward.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/3c2f7cf8_7db546e8 :
PS5, Line 67: for (i = 0; i < c->c1.link_sockets_num; i++)
move declaration here.
http://gerrit.openvpn.net/c/openvpn/+/434/comment/83bc5910_ce7ee80d :
PS5, Line 1500: out_ls);
this looks weird, why the additional line break?
http://gerrit.openvpn.net/c/openvpn/+/434/comment/d8921253_6d30716c :
PS5, Line 2091: int i;
no
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/8bed9745_e6009f9c :
PS5, Line 2712: int i;
no
http://gerrit.openvpn.net/c/openvpn/+/434/comment/1745f5ec_89e42cd1 :
PS5, Line 2726: int i;
no
http://gerrit.openvpn.net/c/openvpn/+/434/comment/8933303c_7cb6783c :
PS5, Line 3809: int i;
no
http://gerrit.openvpn.net/c/openvpn/+/434/comment/6a0a8d89_cbd88193 :
PS5, Line 3830: int i;
no
http://gerrit.openvpn.net/c/openvpn/+/434/comment/18ba15df_e611be9f :
PS5, Line 3898: int i;
no
http://gerrit.openvpn.net/c/openvpn/+/434/comment/586e53d7_2687f6bd :
PS5, Line 4059: int i;
no
File src/openvpn/mtcp.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/03032190_4dfe1132 :
PS5, Line 265: int status, i;
no
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/420473bb_c732efd1 :
PS5, Line 384: int i;
no
File src/openvpn/multi.h:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/d01c4e19_c10b5176 :
PS5, Line 133: bool did_open_context;
doxygen for new members please
File src/openvpn/socket.h:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/ffde4105_327f32dd :
PS5, Line 348: link_socket_init_phase1(struct link_socket *sock, hmm, no?
There must be some better way than an function that has 25 parameters, surely?
http://gerrit.openvpn.net/c/openvpn/+/434/comment/adb96022_106a698b :
PS5, Line 1288: bool sockets_read_residual(const struct context *c); please add minimal documentation
File src/openvpn/socket.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/a2a2981b_f791c838 :
PS5, Line 2239: #if defined (_WIN32)
??
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 5
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Fri, 11 Oct 2024 16:45:43 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, its_Giaan, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: allow tcp/udp server to listen on multiple ports at the same time
......................................................................
Patch Set 5:
(1 comment)
File src/openvpn/multi.h:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/24d0850c_98d08be3 :
PS5, Line 133: bool did_open_context;
Quoted 1 line
doxygen for new members please
This must have been a rebase mistake, because:
commit c252dcc073155567c1982611ec6f065342909287
Author: Arne Schwabe <[email protected]...> Date: Fri Jul 3 11:55:06 2020 +0200
Remove did_open_context, defined and connection_established_flag
Gianmarco will make sure this goes away accordingly.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 5
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 16 Oct 2024 12:51:10 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveAttention is currently required from: flichtenheld, its_Giaan, plaisthos.
its_Giaan has uploaded a new patch set (#6) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Adapt socket handling to support listening on multiple sockets
Introduce internal changes preparing the server to handle multiple sockets concurrently for both TCP and UDP protocols. While no user-visible features are implemented yet, these modifications are essential for enabling future functionality such as listening on multiple ports.
Key changes are: converting link_socket from a single pointer to an array in various contexts, in order to be able to store multiple sockets at once.
---
M src/openvpn/dco.c
M src/openvpn/event.h
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mss.c
M src/openvpn/mtcp.c
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/openvpn.c
M src/openvpn/openvpn.h
M src/openvpn/ping.h
M src/openvpn/socket.c
M src/openvpn/socket.h
17 files changed, 381 insertions(+), 251 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/34/434/6
src/openvpn/dco.c +9 -9
@@ -479,11 +479,11 @@return 0 ; } -struct link_socket *ls = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[0 ]; -ASSERT (ls->info.connection_established); +ASSERT (sock->info.connection_established); -struct sockaddr *remoteaddr = &ls->info.lsa->actual.dest.addr.sa; +struct sockaddr *remoteaddr = &sock->info.lsa->actual.dest.addr.sa;struct tls_multi *multi = c->c2.tls_multi;#ifdef TARGET_FREEBSD /* In Linux in P2P mode the kernel automatically removes an existing peer
@@ -495,7 +495,7 @@ }#endif int ret =dco_new_peer (&c->c1.tuntap->dco, multi->peer_id, - c->c2.link_socket->sd,NULL , remoteaddr,NULL ,NULL ); + c->c2.link_sockets[0 ]->sd,NULL , remoteaddr,NULL ,NULL );if (ret <0 ) {return ret;
@@ -528,12 +528,12 @@#if ENABLE_IP_PKTINFO struct context *c = &mi->context; -if (!proto_is_udp (c->c2.link_socket->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) +if (!proto_is_udp (c->c2.link_sockets[0 ]->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) {return false; } -struct link_socket_actual *actual = &c->c2.link_socket_info->lsa->actual; +struct link_socket_actual *actual = &c->c2.link_socket_infos[0 ]->lsa->actual;switch (actual->dest.addr.sa.sa_family) {
@@ -578,7 +578,7 @@int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 }; -int sd = c->c2.link_socket->sd; +int sd = c->c2.link_sockets[0 ]->sd;if (c->mode ==CM_CHILD_TCP )
@@ -588,8 +588,8 @@ }else { -ASSERT (c->c2.link_socket_info->connection_established); - remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; +ASSERT (c->c2.link_socket_infos[0 ]->connection_established); + remoteaddr = &c->c2.link_socket_infos[0 ]->lsa->actual.dest.addr.sa; }/* In server mode we need to fetch the remote addresses from the push config */
src/openvpn/event.h +1 -0
@@ -141,6 +141,7 @@struct event_arg {event_arg_t type; +bool pending;/* in UDP/P2P mode marks sockets waiting for processing */ union {struct multi_instance *mi;/* if type = EVENT_ARG_MULTI_INSTANCE */ struct link_socket *sock;/* if type = EVENT_ARG_LINK_SOCKET */
src/openvpn/forward.c +32 -18
143 lines not on this page · raw message
src/openvpn/forward.h +14 -10
@@ -231,10 +231,12 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with the -* packet. +* @param c The context structure of the VPN tunnel associated with +* the packet. +* @param out_sock Socket that will be used to send out the packet. +* */ -void process_incoming_tun (struct context *c); +void process_incoming_tun (struct context *c,struct link_socket *out_sock);/**
@@ -246,10 +248,11 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with -* the packet. +* @param c The context structure of the VPN tunnel associated +* with the packet. +* @param in_sock Socket where the packet was received. */ -void process_outgoing_tun (struct context *c); +void process_outgoing_tun (struct context *c,struct link_socket *in_sock);/**************************************************************************/
@@ -304,20 +307,21 @@#define PIPV6_ICMP_NOHOST_SERVER (1<<6) -void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf); +void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf, +struct link_socket *sock);bool schedule_exit (struct context *c);static inline struct link_socket_info *get_link_socket_info (struct context *c) { -if (c->c2.link_socket_info) +if (c->c2.link_socket_infos) { -return c->c2.link_socket_info; +return c->c2.link_socket_infos[0 ]; }else { -return &c->c2.link_socket->info; +return &c->c2.link_sockets[0 ]->info; } }
src/openvpn/init.c +138 -75
402 lines not on this page · raw message
src/openvpn/init.h +2 -1
@@ -95,7 +95,8 @@bool do_deferred_options (struct context *c,const unsigned int found);void inherit_context_child (struct context *dest, -const struct context *src); +const struct context *src, +struct link_socket *ls);void inherit_context_top (struct context *dest,const struct context *src);
src/openvpn/mss.c +1 -1
@@ -357,7 +357,7 @@struct link_socket_info *lsi =get_link_socket_info (c);struct options *o = &c->options; -int pmtu = c->c2.link_socket->mtu; +int pmtu = c->c2.link_sockets[0 ]->mtu;sa_family_t af = lsi->lsa->actual.dest.addr.sa.sa_family;int proto = lsi->proto;
src/openvpn/mtcp.c +35 -20
121 lines not on this page · raw message
src/openvpn/mudp.c +16 -6
@@ -185,7 +185,8 @@*/ struct multi_instance * -multi_get_create_instance_udp (struct multi_context *m,bool *floated) +multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct mroute_addr real = {0 };
@@ -256,7 +257,7 @@* connect-freq but not against connect-freq-initial */ reflect_filter_rate_limit_decrease (m->initial_rate_limiter); - mi =multi_create_instance (m, &real); + mi =multi_create_instance (m, &real, ls);if (mi) {hash_add_fast (hash, bucket, &mi->real, hv, mi);
@@ -317,7 +318,7 @@msg_set_prefix ("Connection Attempt" ); m->top.c2.to_link = m->hmac_reply; m->top.c2.to_link_addr = m->hmac_reply_dest; -process_outgoing_link (&m->top, m->top.c2.link_socket); +process_outgoing_link (&m->top, m->top.c2.link_sockets[0 ]); m->hmac_reply_dest =NULL ; } }
@@ -380,10 +381,19 @@/* Incoming data on UDP port */ else if (status & SOCKET_READ) { -read_incoming_link (&m->top, m->top.c2.link_socket); -if (!IS_SIG (&m->top)) +for (int i =0 ; i < m->top.c1.link_sockets_num; i++) { -multi_process_incoming_link (m,NULL , mpp_flags); +if (!m->top.c2.link_sockets[i]->ev_arg.pending) + { +continue ; + } + +read_incoming_link (&m->top, m->top.c2.link_sockets[i]); +if (!IS_SIG (&m->top)) + { +multi_process_incoming_link (m,NULL , mpp_flags, + m->top.c2.link_sockets[i]); + } } }/* Incoming data on TUN device */
src/openvpn/mudp.h +4 -2
@@ -55,12 +55,14 @@* it. If no entry exists, this function handles its creation, and if * successful, returns the newly created instance. * -* @param m - The single multi_context structure. +* @param m - The single multi_context structure. +* @param ls - Listening socket where this instance is connecting to * * @return A pointer to a multi_instance if one already existed for the * packet's source address or if one was a newly created successfully. * NULL if one did not yet exist and a new one was not created. */ -struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated); +struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls);#endif /* ifndef MUDP_H */
src/openvpn/multi.c +14 -10
@@ -750,7 +750,8 @@* Create a client instance object for a newly connected client. */ struct multi_instance * -multi_create_instance (struct multi_context *m,const struct mroute_addr *real) +multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct multi_instance *mi;
@@ -773,7 +774,7 @@generate_prefix (mi); } -inherit_context_child (&mi->context, &m->top); +inherit_context_child (&mi->context, &m->top, ls);if (IS_SIG (&mi->context)) { goto err;
@@ -3124,7 +3125,8 @@ }void -multi_process_float (struct multi_context *m,struct multi_instance *mi) +multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls) {struct mroute_addr real = {0 };struct hash *hash = m->hash;
@@ -3180,8 +3182,8 @@ mi->context.c2.to_link_addr = &mi->context.c2.from;/* inherit parent link_socket and link_socket_info */ - mi->context.c2.link_socket = m->top.c2.link_socket; - mi->context.c2.link_socket_info->lsa->actual = m->top.c2.from; + mi->context.c2.link_sockets[0 ] = ls; + mi->context.c2.link_socket_infos[0 ]->lsa->actual = m->top.c2.from;tls_update_remote_addr (mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3329,7 +3331,8 @@* i.e. client -> server direction. */ bool -multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags) +multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls) {struct gc_arena gc =gc_new ();
@@ -3350,7 +3353,7 @@#ifdef MULTI_DEBUG_EVENT_LOOP printf ("TCP/UDP -> TUN [%d]\n" ,BLEN (&m->top.c2.buf));#endif -multi_set_pending (m,multi_get_create_instance_udp (m, &floated)); +multi_set_pending (m,multi_get_create_instance_udp (m, &floated, ls)); }else {
@@ -3391,7 +3394,7 @@/* nonzero length means that we have a valid, decrypted packed */ if (floated && c->c2.buf.len >0 ) { -multi_process_float (m, m->pending); +multi_process_float (m, m->pending, ls); }process_incoming_link_part2 (c, lsi, orig_buf);
@@ -3610,7 +3613,7 @@ }/* encrypt in instance context */ -process_incoming_tun (c); +process_incoming_tun (c, c->c2.link_sockets[0 ]);/* postprocess and set wakeup */ ret =multi_process_post (m, m->pending, mpp_flags);
@@ -3642,7 +3645,8 @@ { pip_flags |=PIP_MSSFIX ; } -process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf); +process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf, + item.instance->context.c2.link_sockets[0 ]);encrypt_sign (&item.instance->context, true);mbuf_free_buf (item.buffer);
src/openvpn/multi.h +9 -5
@@ -274,7 +274,8 @@void multi_top_free (struct multi_context *m); -struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real); +struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls);void multi_close_instance (struct multi_context *m,struct multi_instance *mi,bool shutdown);
@@ -288,7 +289,8 @@* existing peer. Updates multi_instance with new address, * updates hashtables in multi_context. */ -void multi_process_float (struct multi_context *m,struct multi_instance *mi); +void multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls);#define MPP_PRE_SELECT (1<<0)#define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -353,8 +355,10 @@* when using TCP transport. Otherwise NULL, as is * the case when using UDP transport. * @param mpp_flags - Fast I/O optimization flags. +* @param ls - Socket where the packet was received. */ -bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags); +bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls);/**
@@ -668,7 +672,7 @@#endif set_prefix (mi);vlan_process_outgoing_tun (m, mi); -process_outgoing_tun (&mi->context); +process_outgoing_tun (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
@@ -683,7 +687,7 @@ {bool ret = true;set_prefix (mi); -process_outgoing_link (&mi->context, mi->context.c2.link_socket); +process_outgoing_link (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
src/openvpn/openvpn.c +1 -1
@@ -91,7 +91,7 @@ }/* process the I/O which triggered select */ -process_io (c, c->c2.link_socket); +process_io (c, c->c2.link_sockets[0 ]);P2P_CHECK_SIG ();perf_pop ();
src/openvpn/openvpn.h +5 -4
@@ -154,7 +154,8 @@*/ struct context_1 { -struct link_socket_addr link_socket_addr; +int link_sockets_num; +struct link_socket_addr *link_socket_addrs;/**< Local and remote addresses on the * external network. */
@@ -237,11 +238,11 @@/* bitmask for event status. Check event.h for possible values */ unsigned int event_set_status; -struct link_socket *link_socket;/* socket used for TCP/UDP connection to remote */ +struct link_socket **link_sockets; +struct link_socket_info **link_socket_infos; +bool link_socket_owned; -/** This variable is used instead link_socket->info for P2MP UDP childs */ -struct link_socket_info *link_socket_info;const struct link_socket *accept_from;/* possibly do accept() on a parent link_socket */ struct link_socket_actual *to_link_addr;/* IP address of remote */
src/openvpn/ping.h +1 -1
@@ -63,7 +63,7 @@ && event_timeout_trigger(&c->c2.ping_rec_interval, &c->c2.timeval, (!c->options.ping_timer_remote - || link_socket_actual_defined(&c->c1.link_socket_addr.actual)) + || link_socket_actual_defined(&c->c1.link_socket_addrs[0].actual)) ? ETT_DEFAULT : 15)) {trigger_ping_timeout_signal (c);
src/openvpn/socket.c +85 -81
297 lines not on this page · raw message
src/openvpn/socket.h +14 -7
@@ -344,9 +344,15 @@/* * Initialize link_socket object. */ -void link_socket_init_phase1 (struct context *c,int mode); +void +link_socket_init_phase1 (struct context *c, +int sock_index, +int mode); -void link_socket_init_phase2 (struct context *c); +void link_socket_init_phase2 (struct context *c, +struct link_socket *sock, +const struct frame *frame, +struct signal_info *sig_info);void do_preresolve (struct context *c);
@@ -1254,11 +1260,12 @@* Socket I/O wait functions */ -static inline bool -socket_read_residual (const struct link_socket *sock) -{ -return sock && sock->stream_buf.residual_fully_formed; -} +/* +* Extends the pre-existing read residual logic +* to all initialized sockets, ensuring the complete +* packet is read. +*/ +bool sockets_read_residual (const struct context *c);static inline event_t socket_event_handle (const struct link_socket *sock)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 6
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveAttention is currently required from: flichtenheld, ordex, plaisthos.
its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Patch Set 6:
(18 comments)
Commit Message:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/1d41d2b6_a8f7ac05 :
PS5, Line 7: allow tcp/udp server to listen on multiple ports at the same time
Quoted 1 line
For a change this fundamental this commit message is not enough. […]
Done
File src/openvpn/forward.h:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/777e4574_22f8383d :
PS5, Line 239: void process_incoming_tun(struct context *c, struct link_socket *out_ls);
Quoted 1 line
I think we have implicitly agreed to call those
out_sock?
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/45aee7e6_1b3916da :
PS5, Line 311: struct link_socket *ls);
Quoted 1 line
let's stick with sock to be consistent?
Done
File src/openvpn/forward.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/25eddf8f_88da1d83 :
PS5, Line 67: for (i = 0; i < c->c1.link_sockets_num; i++)
Quoted 1 line
move declaration here.
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/52741d0c_ed1cfbf5 :
PS5, Line 1500: out_ls);
Quoted 1 line
this looks weird, why the additional line break?
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/c9729dd8_c23a63b3 :
PS5, Line 2091: int i;
Quoted 1 line
no
Done
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/5db88ca1_62001647 :
PS5, Line 2712: int i;
Quoted 1 line
no
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/c4b1d0a7_caefad40 :
PS5, Line 2726: int i;
Quoted 1 line
no
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/d8bf560b_269e4c53 :
PS5, Line 3809: int i;
Quoted 1 line
no
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/3fbce72a_bc8f27b6 :
PS5, Line 3830: int i;
Quoted 1 line
no
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/96692862_fb70f0c5 :
PS5, Line 3898: int i;
Quoted 1 line
no
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/b06654d3_bd9889ea :
PS5, Line 4059: int i;
Quoted 1 line
no
Done
File src/openvpn/mtcp.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/324654a5_bfaf62d1 :
PS5, Line 265: int status, i;
Quoted 1 line
no
Done
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/9eba0158_a12ada55 :
PS5, Line 384: int i;
Quoted 1 line
no
Done
File src/openvpn/multi.h:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/b0f20aa4_59ddfbd1 :
PS5, Line 133: bool did_open_context;
Quoted 1 line
This must have been a rebase mistake, because: […]
It was a rebase mistake indeed, so I removed this.
File src/openvpn/socket.h:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/a49234a5_d2525f23 :
PS5, Line 348: link_socket_init_phase1(struct link_socket *sock,
Quoted 1 line
hmm, no? […]
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/4d71982d_76aa122f :
PS5, Line 1288: bool sockets_read_residual(const struct context *c);
Quoted 1 line
please add minimal documentation
Done
File src/openvpn/socket.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/b48f0b7e_bcabdfe7 :
PS5, Line 2239: #if defined (_WIN32)
Quoted 1 line
??
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 6
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Thu, 17 Oct 2024 14:49:41 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveAttention is currently required from: flichtenheld, ordex, plaisthos.
its_Giaan has uploaded a new patch set (#7) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Adapt socket handling to support listening on multiple sockets
Introduce internal changes preparing the server to handle multiple sockets concurrently for both TCP and UDP protocols. While no user-visible features are implemented yet, these modifications are essential for enabling future functionality such as listening on multiple ports.
Key changes are: converting link_socket from a single pointer to an array in various contexts, in order to be able to store multiple sockets at once.
---
M src/openvpn/dco.c
M src/openvpn/event.h
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mss.c
M src/openvpn/mtcp.c
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/openvpn.c
M src/openvpn/openvpn.h
M src/openvpn/ping.h
M src/openvpn/socket.c
M src/openvpn/socket.h
17 files changed, 380 insertions(+), 251 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/34/434/7
src/openvpn/dco.c +9 -9
@@ -479,11 +479,11 @@return 0 ; } -struct link_socket *ls = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[0 ]; -ASSERT (ls->info.connection_established); +ASSERT (sock->info.connection_established); -struct sockaddr *remoteaddr = &ls->info.lsa->actual.dest.addr.sa; +struct sockaddr *remoteaddr = &sock->info.lsa->actual.dest.addr.sa;struct tls_multi *multi = c->c2.tls_multi;#ifdef TARGET_FREEBSD /* In Linux in P2P mode the kernel automatically removes an existing peer
@@ -495,7 +495,7 @@ }#endif int ret =dco_new_peer (&c->c1.tuntap->dco, multi->peer_id, - c->c2.link_socket->sd,NULL , remoteaddr,NULL ,NULL ); + c->c2.link_sockets[0 ]->sd,NULL , remoteaddr,NULL ,NULL );if (ret <0 ) {return ret;
@@ -528,12 +528,12 @@#if ENABLE_IP_PKTINFO struct context *c = &mi->context; -if (!proto_is_udp (c->c2.link_socket->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) +if (!proto_is_udp (c->c2.link_sockets[0 ]->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) {return false; } -struct link_socket_actual *actual = &c->c2.link_socket_info->lsa->actual; +struct link_socket_actual *actual = &c->c2.link_socket_infos[0 ]->lsa->actual;switch (actual->dest.addr.sa.sa_family) {
@@ -578,7 +578,7 @@int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 }; -int sd = c->c2.link_socket->sd; +int sd = c->c2.link_sockets[0 ]->sd;if (c->mode ==CM_CHILD_TCP )
@@ -588,8 +588,8 @@ }else { -ASSERT (c->c2.link_socket_info->connection_established); - remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; +ASSERT (c->c2.link_socket_infos[0 ]->connection_established); + remoteaddr = &c->c2.link_socket_infos[0 ]->lsa->actual.dest.addr.sa; }/* In server mode we need to fetch the remote addresses from the push config */
src/openvpn/event.h +1 -0
@@ -141,6 +141,7 @@struct event_arg {event_arg_t type; +bool pending;/* in UDP/P2P mode marks sockets waiting for processing */ union {struct multi_instance *mi;/* if type = EVENT_ARG_MULTI_INSTANCE */ struct link_socket *sock;/* if type = EVENT_ARG_LINK_SOCKET */
src/openvpn/forward.c +32 -18
143 lines not on this page · raw message
src/openvpn/forward.h +14 -10
@@ -231,10 +231,12 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with the -* packet. +* @param c The context structure of the VPN tunnel associated with +* the packet. +* @param out_sock Socket that will be used to send out the packet. +* */ -void process_incoming_tun (struct context *c); +void process_incoming_tun (struct context *c,struct link_socket *out_sock);/**
@@ -246,10 +248,11 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with -* the packet. +* @param c The context structure of the VPN tunnel associated +* with the packet. +* @param in_sock Socket where the packet was received. */ -void process_outgoing_tun (struct context *c); +void process_outgoing_tun (struct context *c,struct link_socket *in_sock);/**************************************************************************/
@@ -304,20 +307,21 @@#define PIPV6_ICMP_NOHOST_SERVER (1<<6) -void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf); +void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf, +struct link_socket *sock);bool schedule_exit (struct context *c);static inline struct link_socket_info *get_link_socket_info (struct context *c) { -if (c->c2.link_socket_info) +if (c->c2.link_socket_infos) { -return c->c2.link_socket_info; +return c->c2.link_socket_infos[0 ]; }else { -return &c->c2.link_socket->info; +return &c->c2.link_sockets[0 ]->info; } }
src/openvpn/init.c +138 -75
402 lines not on this page · raw message
src/openvpn/init.h +2 -1
@@ -95,7 +95,8 @@bool do_deferred_options (struct context *c,const unsigned int found);void inherit_context_child (struct context *dest, -const struct context *src); +const struct context *src, +struct link_socket *ls);void inherit_context_top (struct context *dest,const struct context *src);
src/openvpn/mss.c +1 -1
@@ -357,7 +357,7 @@struct link_socket_info *lsi =get_link_socket_info (c);struct options *o = &c->options; -int pmtu = c->c2.link_socket->mtu; +int pmtu = c->c2.link_sockets[0 ]->mtu;sa_family_t af = lsi->lsa->actual.dest.addr.sa.sa_family;int proto = lsi->proto;
src/openvpn/mtcp.c +34 -20
114 lines not on this page · raw message
src/openvpn/mudp.c +16 -6
@@ -185,7 +185,8 @@*/ struct multi_instance * -multi_get_create_instance_udp (struct multi_context *m,bool *floated) +multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct mroute_addr real = {0 };
@@ -256,7 +257,7 @@* connect-freq but not against connect-freq-initial */ reflect_filter_rate_limit_decrease (m->initial_rate_limiter); - mi =multi_create_instance (m, &real); + mi =multi_create_instance (m, &real, ls);if (mi) {hash_add_fast (hash, bucket, &mi->real, hv, mi);
@@ -317,7 +318,7 @@msg_set_prefix ("Connection Attempt" ); m->top.c2.to_link = m->hmac_reply; m->top.c2.to_link_addr = m->hmac_reply_dest; -process_outgoing_link (&m->top, m->top.c2.link_socket); +process_outgoing_link (&m->top, m->top.c2.link_sockets[0 ]); m->hmac_reply_dest =NULL ; } }
@@ -380,10 +381,19 @@/* Incoming data on UDP port */ else if (status & SOCKET_READ) { -read_incoming_link (&m->top, m->top.c2.link_socket); -if (!IS_SIG (&m->top)) +for (int i =0 ; i < m->top.c1.link_sockets_num; i++) { -multi_process_incoming_link (m,NULL , mpp_flags); +if (!m->top.c2.link_sockets[i]->ev_arg.pending) + { +continue ; + } + +read_incoming_link (&m->top, m->top.c2.link_sockets[i]); +if (!IS_SIG (&m->top)) + { +multi_process_incoming_link (m,NULL , mpp_flags, + m->top.c2.link_sockets[i]); + } } }/* Incoming data on TUN device */
src/openvpn/mudp.h +4 -2
@@ -55,12 +55,14 @@* it. If no entry exists, this function handles its creation, and if * successful, returns the newly created instance. * -* @param m - The single multi_context structure. +* @param m - The single multi_context structure. +* @param ls - Listening socket where this instance is connecting to * * @return A pointer to a multi_instance if one already existed for the * packet's source address or if one was a newly created successfully. * NULL if one did not yet exist and a new one was not created. */ -struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated); +struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls);#endif /* ifndef MUDP_H */
src/openvpn/multi.c +14 -10
@@ -750,7 +750,8 @@* Create a client instance object for a newly connected client. */ struct multi_instance * -multi_create_instance (struct multi_context *m,const struct mroute_addr *real) +multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct multi_instance *mi;
@@ -773,7 +774,7 @@generate_prefix (mi); } -inherit_context_child (&mi->context, &m->top); +inherit_context_child (&mi->context, &m->top, ls);if (IS_SIG (&mi->context)) { goto err;
@@ -3124,7 +3125,8 @@ }void -multi_process_float (struct multi_context *m,struct multi_instance *mi) +multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls) {struct mroute_addr real = {0 };struct hash *hash = m->hash;
@@ -3180,8 +3182,8 @@ mi->context.c2.to_link_addr = &mi->context.c2.from;/* inherit parent link_socket and link_socket_info */ - mi->context.c2.link_socket = m->top.c2.link_socket; - mi->context.c2.link_socket_info->lsa->actual = m->top.c2.from; + mi->context.c2.link_sockets[0 ] = ls; + mi->context.c2.link_socket_infos[0 ]->lsa->actual = m->top.c2.from;tls_update_remote_addr (mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3329,7 +3331,8 @@* i.e. client -> server direction. */ bool -multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags) +multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls) {struct gc_arena gc =gc_new ();
@@ -3350,7 +3353,7 @@#ifdef MULTI_DEBUG_EVENT_LOOP printf ("TCP/UDP -> TUN [%d]\n" ,BLEN (&m->top.c2.buf));#endif -multi_set_pending (m,multi_get_create_instance_udp (m, &floated)); +multi_set_pending (m,multi_get_create_instance_udp (m, &floated, ls)); }else {
@@ -3391,7 +3394,7 @@/* nonzero length means that we have a valid, decrypted packed */ if (floated && c->c2.buf.len >0 ) { -multi_process_float (m, m->pending); +multi_process_float (m, m->pending, ls); }process_incoming_link_part2 (c, lsi, orig_buf);
@@ -3610,7 +3613,7 @@ }/* encrypt in instance context */ -process_incoming_tun (c); +process_incoming_tun (c, c->c2.link_sockets[0 ]);/* postprocess and set wakeup */ ret =multi_process_post (m, m->pending, mpp_flags);
@@ -3642,7 +3645,8 @@ { pip_flags |=PIP_MSSFIX ; } -process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf); +process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf, + item.instance->context.c2.link_sockets[0 ]);encrypt_sign (&item.instance->context, true);mbuf_free_buf (item.buffer);
src/openvpn/multi.h +9 -5
@@ -274,7 +274,8 @@void multi_top_free (struct multi_context *m); -struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real); +struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls);void multi_close_instance (struct multi_context *m,struct multi_instance *mi,bool shutdown);
@@ -288,7 +289,8 @@* existing peer. Updates multi_instance with new address, * updates hashtables in multi_context. */ -void multi_process_float (struct multi_context *m,struct multi_instance *mi); +void multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls);#define MPP_PRE_SELECT (1<<0)#define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -353,8 +355,10 @@* when using TCP transport. Otherwise NULL, as is * the case when using UDP transport. * @param mpp_flags - Fast I/O optimization flags. +* @param ls - Socket where the packet was received. */ -bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags); +bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls);/**
@@ -668,7 +672,7 @@#endif set_prefix (mi);vlan_process_outgoing_tun (m, mi); -process_outgoing_tun (&mi->context); +process_outgoing_tun (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
@@ -683,7 +687,7 @@ {bool ret = true;set_prefix (mi); -process_outgoing_link (&mi->context, mi->context.c2.link_socket); +process_outgoing_link (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
src/openvpn/openvpn.c +1 -1
@@ -91,7 +91,7 @@ }/* process the I/O which triggered select */ -process_io (c, c->c2.link_socket); +process_io (c, c->c2.link_sockets[0 ]);P2P_CHECK_SIG ();perf_pop ();
src/openvpn/openvpn.h +5 -4
@@ -154,7 +154,8 @@*/ struct context_1 { -struct link_socket_addr link_socket_addr; +int link_sockets_num; +struct link_socket_addr *link_socket_addrs;/**< Local and remote addresses on the * external network. */
@@ -233,11 +234,11 @@/* bitmask for event status. Check event.h for possible values */ unsigned int event_set_status; -struct link_socket *link_socket;/* socket used for TCP/UDP connection to remote */ +struct link_socket **link_sockets; +struct link_socket_info **link_socket_infos; +bool link_socket_owned; -/** This variable is used instead link_socket->info for P2MP UDP childs */ -struct link_socket_info *link_socket_info;const struct link_socket *accept_from;/* possibly do accept() on a parent link_socket */ struct link_socket_actual *to_link_addr;/* IP address of remote */
src/openvpn/ping.h +1 -1
@@ -63,7 +63,7 @@ && event_timeout_trigger(&c->c2.ping_rec_interval, &c->c2.timeval, (!c->options.ping_timer_remote - || link_socket_actual_defined(&c->c1.link_socket_addr.actual)) + || link_socket_actual_defined(&c->c1.link_socket_addrs[0].actual)) ? ETT_DEFAULT : 15)) {trigger_ping_timeout_signal (c);
src/openvpn/socket.c +85 -81
297 lines not on this page · raw message
src/openvpn/socket.h +14 -7
@@ -344,9 +344,15 @@/* * Initialize link_socket object. */ -void link_socket_init_phase1 (struct context *c,int mode); +void +link_socket_init_phase1 (struct context *c, +int sock_index, +int mode); -void link_socket_init_phase2 (struct context *c); +void link_socket_init_phase2 (struct context *c, +struct link_socket *sock, +const struct frame *frame, +struct signal_info *sig_info);void do_preresolve (struct context *c);
@@ -1228,11 +1234,12 @@* Socket I/O wait functions */ -static inline bool -socket_read_residual (const struct link_socket *sock) -{ -return sock && sock->stream_buf.residual_fully_formed; -} +/* +* Extends the pre-existing read residual logic +* to all initialized sockets, ensuring the complete +* packet is read. +*/ +bool sockets_read_residual (const struct context *c);static inline event_t socket_event_handle (const struct link_socket *sock)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 7
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveAttention is currently required from: ordex, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Patch Set 7: -Code-Review
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 7
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 06 Nov 2024 13:15:49 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, ordex, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Patch Set 7: Code-Review-2
(17 comments)
Patchset:
PS7:
Okay, this is a big one.
There is minor things - whitespace changes that should not be done, or wrapping changes that are not called for. There are some parts that I just do not understand which would benefit from comments in the code *or* comments here in gerrit ("will be resolved by the next patch in the series").
There's ugliness (link_socket_init_phase1(), the patch looks excessive for what it intends to do).
There are at least 3 places that look like rebase accidents, and need to be very carefully checked for "is this change intentional".
File src/openvpn/forward.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/af521d3c_72b59ce8 :
PS7, Line 1133: /* all sockets are of the same type, so just check the first one */
this confuses me. We will have UDP and TCP sockets later on, so they are not expected to be "all of the same type". Will this be addressed later in the patch series?
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/e3b56022_c021a1c0 :
PS7, Line 533: {
this is a behavioural change, not checking advance_next_remote anymore. Is this intentional or a rebase artefact?
http://gerrit.openvpn.net/c/openvpn/+/434/comment/d9600958_55933535 :
PS7, Line 1959: ASSERT(c->c2.link_sockets);
this is not doing the same thing as before... so we do not know if link_sockets[0] is actually well defined here. No?
http://gerrit.openvpn.net/c/openvpn/+/434/comment/f4f59153_2fd3ff1d :
PS7, Line 2015: do_ifconfig(c->c1.tuntap, c->c1.tuntap->actual_name, c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx);
line length exceeded, and the old version wasn't that bad (the unwrapping above was reasonable, with just a few characters hanging in the next line, but this one should stay as it is).
Also, quite unrelated to the patch itself... just sayin.
http://gerrit.openvpn.net/c/openvpn/+/434/comment/2d3860a3_9d493c40 :
PS7, Line 3819: do_init_socket_1(struct context *c)
I think we should stick to phase1 as function name, otherwise it reads as if this is "init socket 1", and "init socket 2" for "socket #1 and #2". No?
http://gerrit.openvpn.net/c/openvpn/+/434/comment/f10b10f2_22a5be55 :
PS7, Line 4011: if (c->c2.link_sockets && c->c2.link_socket_owned)
what happened to the is_dco_win() part here? This looks like a rebase accident
http://gerrit.openvpn.net/c/openvpn/+/434/comment/72fd22c0_b99b4657 :
PS7, Line 4040: CLEAR(c->c1.link_socket_addrs[0].actual);
this looks inconsistent - freeaddrinfo() is called in the loop, while the CLEAR() is only called for [0]. Intentional? If yes, a comment should say so.
(I could see this as being intentional "because this is client side only, and client only has 1 socket, ever", but it looks weird)
http://gerrit.openvpn.net/c/openvpn/+/434/comment/b96d510f_3ce9a525 :
PS7, Line 4719: do_init_socket_1(c);
mmmh, see comment above, maybe name this do_init_link_sockets_phase1()?
do_init_socket_1() could be anything...
http://gerrit.openvpn.net/c/openvpn/+/434/comment/e0ffc177_bec7efd2 :
PS7, Line 4762: do_init_socket_2(c);_phase2()
http://gerrit.openvpn.net/c/openvpn/+/434/comment/1785554f_4c253f1b :
PS7, Line 4968: &dest->gc);
is this wrapping necessary? Comparing to the lines below it does not seem like it
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/ed1d30f4_2e4e41d3 :
PS7, Line 384: for (int i = 0; i < m->top.c1.link_sockets_num; i++)
this, again, is confusing me. So is this a client instance ("1 socket exists") or the server instance ("all sockets exists, but sockets can be UDP and TCP")? Having the _udp() handler walk through the list of sockets which could be "more than 1, and such, UDP or TCP" does not look right, at least not without some explanation ("this will all move to a common multi_process_io_anything() in the next patch") ;-)
File src/openvpn/socket.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/efd059f1_5a25f7ad :
PS7, Line 1858: c->c2.link_sockets[sock_index]->local_host = c->options.ce.local;
Can this be changed to *sock = &c->c2.link_sockets[sock_index] and then the rest of the function can be left unchanged? this is how all the other parts of the patch do it... (not [0] in this case, of course).
http://gerrit.openvpn.net/c/openvpn/+/434/comment/b3f1e813_3ace2227 :
PS7, Line 2222: #if defined (_WIN32)
unrelated whitespace change, please do not (also, this extra space is not how it's done elsewhere)
http://gerrit.openvpn.net/c/openvpn/+/434/comment/2e93e0ee_51a6abd7 :
PS7, Line 2259: sig_info->signal_received = SIGUSR1;
I think this is a rebase artefact, the multisocket patch colliding with Selva's signal handler reworking. Please double-check, but this does not look right.
http://gerrit.openvpn.net/c/openvpn/+/434/comment/fa7b3095_61edff01 :
PS7, Line 2271: sig_info);
please do not wrap. The line is not long and not changed by this patch.
http://gerrit.openvpn.net/c/openvpn/+/434/comment/02a03a9a_2d541041 :
PS7, Line 2297: if (sig_save)
again, please thoroughly double check. I think this is old code, and the throw_signal() stuff is how it should be.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 7
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 27 Nov 2024 15:54:14 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Patch Set 7:
(1 comment)
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/4ecc2f55_682f2236 :
PS7, Line 384: for (int i = 0; i < m->top.c1.link_sockets_num; i++)
Quoted 1 line
this, again, is confusing me. […]
this comment opened a little pandora's box...which indeed made us question a little more the context where multi_process_io_udp() get invoked. This indeed may use a little cleanup.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 7
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Fri, 06 Dec 2024 14:56:40 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, plaisthos.
its_Giaan has uploaded a new patch set (#8) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Adapt socket handling to support listening on multiple sockets
Introduce internal changes preparing the server to handle multiple sockets concurrently for both TCP and UDP protocols. While no user-visible features are implemented yet, these modifications are essential for enabling future functionality such as listening on multiple ports.
Key changes are: converting link_socket from a single pointer to an array in various contexts, in order to be able to store multiple sockets at once.
---
M src/openvpn/dco.c
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mss.c
M src/openvpn/mtcp.c
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/openvpn.c
M src/openvpn/openvpn.h
M src/openvpn/ping.h
M src/openvpn/socket.c
M src/openvpn/socket.h
16 files changed, 328 insertions(+), 186 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/34/434/8
src/openvpn/dco.c +9 -9
@@ -478,11 +478,11 @@return 0 ; } -struct link_socket *ls = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[0 ]; -ASSERT (ls->info.connection_established); +ASSERT (sock->info.connection_established); -struct sockaddr *remoteaddr = &ls->info.lsa->actual.dest.addr.sa; +struct sockaddr *remoteaddr = &sock->info.lsa->actual.dest.addr.sa;struct tls_multi *multi = c->c2.tls_multi;#ifdef TARGET_FREEBSD /* In Linux in P2P mode the kernel automatically removes an existing peer
@@ -494,7 +494,7 @@ }#endif int ret =dco_new_peer (&c->c1.tuntap->dco, multi->peer_id, - c->c2.link_socket->sd,NULL , remoteaddr,NULL ,NULL ); + c->c2.link_sockets[0 ]->sd,NULL , remoteaddr,NULL ,NULL );if (ret <0 ) {return ret;
@@ -527,12 +527,12 @@#if ENABLE_IP_PKTINFO struct context *c = &mi->context; -if (!proto_is_udp (c->c2.link_socket->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) +if (!proto_is_udp (c->c2.link_sockets[0 ]->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) {return false; } -struct link_socket_actual *actual = &c->c2.link_socket_info->lsa->actual; +struct link_socket_actual *actual = &c->c2.link_socket_infos[0 ]->lsa->actual;switch (actual->dest.addr.sa.sa_family) {
@@ -577,7 +577,7 @@int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 }; -int sd = c->c2.link_socket->sd; +int sd = c->c2.link_sockets[0 ]->sd;if (c->mode ==CM_CHILD_TCP )
@@ -587,8 +587,8 @@ }else { -ASSERT (c->c2.link_socket_info->connection_established); - remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; +ASSERT (c->c2.link_socket_infos[0 ]->connection_established); + remoteaddr = &c->c2.link_socket_infos[0 ]->lsa->actual.dest.addr.sa; }/* In server mode we need to fetch the remote addresses from the push config */
src/openvpn/forward.c +29 -18
134 lines not on this page · raw message
src/openvpn/forward.h +14 -10
@@ -231,10 +231,12 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with the -* packet. +* @param c The context structure of the VPN tunnel associated with +* the packet. +* @param out_sock Socket that will be used to send out the packet. +* */ -void process_incoming_tun (struct context *c); +void process_incoming_tun (struct context *c,struct link_socket *out_sock);/**
@@ -246,10 +248,11 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with -* the packet. +* @param c The context structure of the VPN tunnel associated +* with the packet. +* @param in_sock Socket where the packet was received. */ -void process_outgoing_tun (struct context *c); +void process_outgoing_tun (struct context *c,struct link_socket *in_sock);/**************************************************************************/
@@ -304,20 +307,21 @@#define PIPV6_ICMP_NOHOST_SERVER (1<<6) -void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf); +void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf, +struct link_socket *sock);bool schedule_exit (struct context *c);static inline struct link_socket_info *get_link_socket_info (struct context *c) { -if (c->c2.link_socket_info) +if (c->c2.link_socket_infos) { -return c->c2.link_socket_info; +return c->c2.link_socket_infos[0 ]; }else { -return &c->c2.link_socket->info; +return &c->c2.link_sockets[0 ]->info; } }
src/openvpn/init.c +146 -67
399 lines not on this page · raw message
src/openvpn/init.h +2 -1
@@ -95,7 +95,8 @@bool do_deferred_options (struct context *c,const unsigned int found);void inherit_context_child (struct context *dest, -const struct context *src); +const struct context *src, +struct link_socket *ls);void inherit_context_top (struct context *dest,const struct context *src);
src/openvpn/mss.c +1 -1
@@ -357,7 +357,7 @@struct link_socket_info *lsi =get_link_socket_info (c);struct options *o = &c->options; -int pmtu = c->c2.link_socket->mtu; +int pmtu = c->c2.link_sockets[0 ]->mtu;sa_family_t af = lsi->lsa->actual.dest.addr.sa.sa_family;int proto = lsi->proto;
src/openvpn/mtcp.c +34 -20
114 lines not on this page · raw message
src/openvpn/mudp.c +13 -7
@@ -185,7 +185,8 @@*/ struct multi_instance * -multi_get_create_instance_udp (struct multi_context *m,bool *floated) +multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct mroute_addr real = {0 };
@@ -256,7 +257,7 @@* connect-freq but not against connect-freq-initial */ reflect_filter_rate_limit_decrease (m->initial_rate_limiter); - mi =multi_create_instance (m, &real); + mi =multi_create_instance (m, &real, ls);if (mi) {hash_add_fast (hash, bucket, &mi->real, hv, mi);
@@ -317,7 +318,7 @@msg_set_prefix ("Connection Attempt" ); m->top.c2.to_link = m->hmac_reply; m->top.c2.to_link_addr = m->hmac_reply_dest; -process_outgoing_link (&m->top, m->top.c2.link_socket); +process_outgoing_link (&m->top, m->top.c2.link_sockets[0 ]); m->hmac_reply_dest =NULL ; } }
@@ -326,7 +327,7 @@* Process an I/O event. */ static void -multi_process_io_udp (struct multi_context *m) +multi_process_io_udp (struct multi_context *m,struct link_socket *sock) {const unsigned int status = m->top.c2.event_set_status;const unsigned int mpp_flags = m->top.c2.fast_io
@@ -380,10 +381,11 @@/* Incoming data on UDP port */ else if (status & SOCKET_READ) { -read_incoming_link (&m->top, m->top.c2.link_socket); +read_incoming_link (&m->top, sock);if (!IS_SIG (&m->top)) { -multi_process_incoming_link (m,NULL , mpp_flags); +multi_process_incoming_link (m,NULL , mpp_flags, + sock); } }/* Incoming data on TUN device */
@@ -514,7 +516,11 @@else {/* process I/O */ -multi_process_io_udp (&multi); + +/* Since there's only one link_socket just use the first, in an upcoming +* patch this will be changed by using the link_socket returned by the +* event set */ +multi_process_io_udp (&multi, top->c2.link_sockets[0 ]);MULTI_CHECK_SIG (&multi); }
src/openvpn/mudp.h +4 -2
@@ -55,12 +55,14 @@* it. If no entry exists, this function handles its creation, and if * successful, returns the newly created instance. * -* @param m - The single multi_context structure. +* @param m - The single multi_context structure. +* @param ls - Listening socket where this instance is connecting to * * @return A pointer to a multi_instance if one already existed for the * packet's source address or if one was a newly created successfully. * NULL if one did not yet exist and a new one was not created. */ -struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated); +struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls);#endif /* ifndef MUDP_H */
src/openvpn/multi.c +14 -10
@@ -750,7 +750,8 @@* Create a client instance object for a newly connected client. */ struct multi_instance * -multi_create_instance (struct multi_context *m,const struct mroute_addr *real) +multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct multi_instance *mi;
@@ -773,7 +774,7 @@generate_prefix (mi); } -inherit_context_child (&mi->context, &m->top); +inherit_context_child (&mi->context, &m->top, ls);if (IS_SIG (&mi->context)) { goto err;
@@ -3124,7 +3125,8 @@ }void -multi_process_float (struct multi_context *m,struct multi_instance *mi) +multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls) {struct mroute_addr real = {0 };struct hash *hash = m->hash;
@@ -3180,8 +3182,8 @@ mi->context.c2.to_link_addr = &mi->context.c2.from;/* inherit parent link_socket and link_socket_info */ - mi->context.c2.link_socket = m->top.c2.link_socket; - mi->context.c2.link_socket_info->lsa->actual = m->top.c2.from; + mi->context.c2.link_sockets[0 ] = ls; + mi->context.c2.link_socket_infos[0 ]->lsa->actual = m->top.c2.from;tls_update_remote_addr (mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3329,7 +3331,8 @@* i.e. client -> server direction. */ bool -multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags) +multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls) {struct gc_arena gc =gc_new ();
@@ -3350,7 +3353,7 @@#ifdef MULTI_DEBUG_EVENT_LOOP printf ("TCP/UDP -> TUN [%d]\n" ,BLEN (&m->top.c2.buf));#endif -multi_set_pending (m,multi_get_create_instance_udp (m, &floated)); +multi_set_pending (m,multi_get_create_instance_udp (m, &floated, ls)); }else {
@@ -3391,7 +3394,7 @@/* nonzero length means that we have a valid, decrypted packed */ if (floated && c->c2.buf.len >0 ) { -multi_process_float (m, m->pending); +multi_process_float (m, m->pending, ls); }process_incoming_link_part2 (c, lsi, orig_buf);
@@ -3610,7 +3613,7 @@ }/* encrypt in instance context */ -process_incoming_tun (c); +process_incoming_tun (c, c->c2.link_sockets[0 ]);/* postprocess and set wakeup */ ret =multi_process_post (m, m->pending, mpp_flags);
@@ -3642,7 +3645,8 @@ { pip_flags |=PIP_MSSFIX ; } -process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf); +process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf, + item.instance->context.c2.link_sockets[0 ]);encrypt_sign (&item.instance->context, true);mbuf_free_buf (item.buffer);
src/openvpn/multi.h +9 -5
@@ -274,7 +274,8 @@void multi_top_free (struct multi_context *m); -struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real); +struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls);void multi_close_instance (struct multi_context *m,struct multi_instance *mi,bool shutdown);
@@ -288,7 +289,8 @@* existing peer. Updates multi_instance with new address, * updates hashtables in multi_context. */ -void multi_process_float (struct multi_context *m,struct multi_instance *mi); +void multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls);#define MPP_PRE_SELECT (1<<0)#define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -353,8 +355,10 @@* when using TCP transport. Otherwise NULL, as is * the case when using UDP transport. * @param mpp_flags - Fast I/O optimization flags. +* @param ls - Socket where the packet was received. */ -bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags); +bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls);/**
@@ -668,7 +672,7 @@#endif set_prefix (mi);vlan_process_outgoing_tun (m, mi); -process_outgoing_tun (&mi->context); +process_outgoing_tun (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
@@ -683,7 +687,7 @@ {bool ret = true;set_prefix (mi); -process_outgoing_link (&mi->context, mi->context.c2.link_socket); +process_outgoing_link (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
src/openvpn/openvpn.c +1 -1
@@ -91,7 +91,7 @@ }/* process the I/O which triggered select */ -process_io (c, c->c2.link_socket); +process_io (c, c->c2.link_sockets[0 ]);P2P_CHECK_SIG ();perf_pop ();
src/openvpn/openvpn.h +5 -4
@@ -154,7 +154,8 @@*/ struct context_1 { -struct link_socket_addr link_socket_addr; +int link_sockets_num; +struct link_socket_addr *link_socket_addrs;/**< Local and remote addresses on the * external network. */
@@ -233,11 +234,11 @@/* bitmask for event status. Check event.h for possible values */ unsigned int event_set_status; -struct link_socket *link_socket;/* socket used for TCP/UDP connection to remote */ +struct link_socket **link_sockets; +struct link_socket_info **link_socket_infos; +bool link_socket_owned; -/** This variable is used instead link_socket->info for P2MP UDP childs */ -struct link_socket_info *link_socket_info;const struct link_socket *accept_from;/* possibly do accept() on a parent link_socket */ struct link_socket_actual *to_link_addr;/* IP address of remote */
src/openvpn/ping.h +1 -1
@@ -63,7 +63,7 @@ && event_timeout_trigger(&c->c2.ping_rec_interval, &c->c2.timeval, (!c->options.ping_timer_remote - || link_socket_actual_defined(&c->c1.link_socket_addr.actual)) + || link_socket_actual_defined(&c->c1.link_socket_addrs[0].actual)) ? ETT_DEFAULT : 15)) {trigger_ping_timeout_signal (c);
src/openvpn/socket.c +34 -23
153 lines not on this page · raw message
src/openvpn/socket.h +12 -7
@@ -344,9 +344,13 @@/* * Initialize link_socket object. */ -void link_socket_init_phase1 (struct context *c,int mode); +void +link_socket_init_phase1 (struct context *c, +int sock_index, +int mode); -void link_socket_init_phase2 (struct context *c); +void link_socket_init_phase2 (struct context *c, +struct link_socket *sock);void do_preresolve (struct context *c);
@@ -1228,11 +1232,12 @@* Socket I/O wait functions */ -static inline bool -socket_read_residual (const struct link_socket *sock) -{ -return sock && sock->stream_buf.residual_fully_formed; -} +/* +* Extends the pre-existing read residual logic +* to all initialized sockets, ensuring the complete +* packet is read. +*/ +bool sockets_read_residual (const struct context *c);static inline event_t socket_event_handle (const struct link_socket *sock)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 8
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveAttention is currently required from: cron2, ordex, plaisthos.
its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Patch Set 7:
(16 comments)
File src/openvpn/forward.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/5c3d2260_ff08a995 :
PS7, Line 1133: /* all sockets are of the same type, so just check the first one */
Quoted 1 line
this confuses me. […]
Done
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/c8bba806_c5354795 :
PS7, Line 533: {
Quoted 1 line
this is a behavioural change, not checking
advance_next_remoteanymore. […]
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/0274c355_3b2e8c19 :
PS7, Line 1959: ASSERT(c->c2.link_sockets);
Quoted 1 line
this is not doing the same thing as before... […]
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/9e623ad9_318662fe :
PS7, Line 2015: do_ifconfig(c->c1.tuntap, c->c1.tuntap->actual_name, c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx);
Quoted 1 line
line length exceeded, and the old version wasn't that bad (the unwrapping above was reasonable, with […]
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/83e1f2b3_82aeffb6 :
PS7, Line 3819: do_init_socket_1(struct context *c)
Quoted 1 line
I think we should stick to
phase1as function name, otherwise it reads as if this is "init socket […]
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/983be341_eb72cb9c :
PS7, Line 4011: if (c->c2.link_sockets && c->c2.link_socket_owned)
Quoted 1 line
what happened to the
is_dco_win()part here? This looks like a rebase accident
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/0dd0c10f_cbddc037 :
PS7, Line 4040: CLEAR(c->c1.link_socket_addrs[0].actual);
Quoted 1 line
this looks inconsistent -
freeaddrinfo()is called in the loop, while theCLEAR()is only called for […]
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/8c4402d6_a5c9227d :
PS7, Line 4719: do_init_socket_1(c);
Quoted 1 line
mmmh, see comment above, maybe name this
do_init_link_sockets_phase1()? […]
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/90c989e7_e8b47bfa :
PS7, Line 4762: do_init_socket_2(c);
Quoted 1 line
_phase2()
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/da819cb1_03b64f6a :
PS7, Line 4968: &dest->gc);
Quoted 1 line
is this wrapping necessary? Comparing to the lines below it does not seem like it
Acknowledged
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/d1d68fc6_23406680 :
PS7, Line 384: for (int i = 0; i < m->top.c1.link_sockets_num; i++)
Quoted 1 line
this comment opened a little pandora's box... […]
In the next patches we will have a common server loop for both TCP and UDP however the I/O processing will remain separate, for this specific case we decided to pass directly the link_socket to avoid to walk through all of them, in the final patch we will handle directly the link_socket returned by the event_set.
File src/openvpn/socket.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/6534f7ed_de52f295 :
PS7, Line 1858: c->c2.link_sockets[sock_index]->local_host = c->options.ce.local;
Quoted 1 line
Can this be changed to `*sock =
&c->c2. […]
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/b247da87_2274fb46 :
PS7, Line 2222: #if defined (_WIN32)
Quoted 1 line
unrelated whitespace change, please do not (also, this extra space is not how it's done elsewhere)
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/58256377_1c734eb8 :
PS7, Line 2259: sig_info->signal_received = SIGUSR1;
Quoted 1 line
I think this is a rebase artefact, the multisocket patch colliding with Selva's signal handler rewor […]
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/72e83319_3a6cdcc6 :
PS7, Line 2271: sig_info);
Quoted 1 line
please do not wrap. The line is not long and not changed by this patch.
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/93ac21b3_d36b9855 :
PS7, Line 2297: if (sig_save)
Quoted 1 line
again, please thoroughly double check. […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 7
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Tue, 10 Dec 2024 13:10:35 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveAttention is currently required from: cron2, ordex, plaisthos.
its_Giaan has uploaded a new patch set (#9) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Adapt socket handling to support listening on multiple sockets
Introduce internal changes preparing the server to handle multiple sockets concurrently for both TCP and UDP protocols. While no user-visible features are implemented yet, these modifications are essential for enabling future functionality such as listening on multiple ports.
Key changes are: converting link_socket from a single pointer to an array in various contexts, in order to be able to store multiple sockets at once.
---
M src/openvpn/dco.c
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mss.c
M src/openvpn/mtcp.c
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/openvpn.c
M src/openvpn/openvpn.h
M src/openvpn/ping.h
M src/openvpn/socket.c
M src/openvpn/socket.h
16 files changed, 327 insertions(+), 186 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/34/434/9
src/openvpn/dco.c +9 -9
@@ -478,11 +478,11 @@return 0 ; } -struct link_socket *ls = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[0 ]; -ASSERT (ls->info.connection_established); +ASSERT (sock->info.connection_established); -struct sockaddr *remoteaddr = &ls->info.lsa->actual.dest.addr.sa; +struct sockaddr *remoteaddr = &sock->info.lsa->actual.dest.addr.sa;struct tls_multi *multi = c->c2.tls_multi;#ifdef TARGET_FREEBSD /* In Linux in P2P mode the kernel automatically removes an existing peer
@@ -494,7 +494,7 @@ }#endif int ret =dco_new_peer (&c->c1.tuntap->dco, multi->peer_id, - c->c2.link_socket->sd,NULL , remoteaddr,NULL ,NULL ); + c->c2.link_sockets[0 ]->sd,NULL , remoteaddr,NULL ,NULL );if (ret <0 ) {return ret;
@@ -527,12 +527,12 @@#if ENABLE_IP_PKTINFO struct context *c = &mi->context; -if (!proto_is_udp (c->c2.link_socket->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) +if (!proto_is_udp (c->c2.link_sockets[0 ]->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) {return false; } -struct link_socket_actual *actual = &c->c2.link_socket_info->lsa->actual; +struct link_socket_actual *actual = &c->c2.link_socket_infos[0 ]->lsa->actual;switch (actual->dest.addr.sa.sa_family) {
@@ -577,7 +577,7 @@int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 }; -int sd = c->c2.link_socket->sd; +int sd = c->c2.link_sockets[0 ]->sd;if (c->mode ==CM_CHILD_TCP )
@@ -587,8 +587,8 @@ }else { -ASSERT (c->c2.link_socket_info->connection_established); - remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; +ASSERT (c->c2.link_socket_infos[0 ]->connection_established); + remoteaddr = &c->c2.link_socket_infos[0 ]->lsa->actual.dest.addr.sa; }/* In server mode we need to fetch the remote addresses from the push config */
src/openvpn/forward.c +29 -18
134 lines not on this page · raw message
src/openvpn/forward.h +14 -10
@@ -231,10 +231,12 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with the -* packet. +* @param c The context structure of the VPN tunnel associated with +* the packet. +* @param out_sock Socket that will be used to send out the packet. +* */ -void process_incoming_tun (struct context *c); +void process_incoming_tun (struct context *c,struct link_socket *out_sock);/**
@@ -246,10 +248,11 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with -* the packet. +* @param c The context structure of the VPN tunnel associated +* with the packet. +* @param in_sock Socket where the packet was received. */ -void process_outgoing_tun (struct context *c); +void process_outgoing_tun (struct context *c,struct link_socket *in_sock);/**************************************************************************/
@@ -304,20 +307,21 @@#define PIPV6_ICMP_NOHOST_SERVER (1<<6) -void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf); +void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf, +struct link_socket *sock);bool schedule_exit (struct context *c);static inline struct link_socket_info *get_link_socket_info (struct context *c) { -if (c->c2.link_socket_info) +if (c->c2.link_socket_infos) { -return c->c2.link_socket_info; +return c->c2.link_socket_infos[0 ]; }else { -return &c->c2.link_socket->info; +return &c->c2.link_sockets[0 ]->info; } }
src/openvpn/init.c +145 -67
398 lines not on this page · raw message
src/openvpn/init.h +2 -1
@@ -95,7 +95,8 @@bool do_deferred_options (struct context *c,const unsigned int found);void inherit_context_child (struct context *dest, -const struct context *src); +const struct context *src, +struct link_socket *ls);void inherit_context_top (struct context *dest,const struct context *src);
src/openvpn/mss.c +1 -1
@@ -357,7 +357,7 @@struct link_socket_info *lsi =get_link_socket_info (c);struct options *o = &c->options; -int pmtu = c->c2.link_socket->mtu; +int pmtu = c->c2.link_sockets[0 ]->mtu;sa_family_t af = lsi->lsa->actual.dest.addr.sa.sa_family;int proto = lsi->proto;
src/openvpn/mtcp.c +34 -20
114 lines not on this page · raw message
src/openvpn/mudp.c +13 -7
@@ -185,7 +185,8 @@*/ struct multi_instance * -multi_get_create_instance_udp (struct multi_context *m,bool *floated) +multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct mroute_addr real = {0 };
@@ -256,7 +257,7 @@* connect-freq but not against connect-freq-initial */ reflect_filter_rate_limit_decrease (m->initial_rate_limiter); - mi =multi_create_instance (m, &real); + mi =multi_create_instance (m, &real, ls);if (mi) {hash_add_fast (hash, bucket, &mi->real, hv, mi);
@@ -317,7 +318,7 @@msg_set_prefix ("Connection Attempt" ); m->top.c2.to_link = m->hmac_reply; m->top.c2.to_link_addr = m->hmac_reply_dest; -process_outgoing_link (&m->top, m->top.c2.link_socket); +process_outgoing_link (&m->top, m->top.c2.link_sockets[0 ]); m->hmac_reply_dest =NULL ; } }
@@ -326,7 +327,7 @@* Process an I/O event. */ static void -multi_process_io_udp (struct multi_context *m) +multi_process_io_udp (struct multi_context *m,struct link_socket *sock) {const unsigned int status = m->top.c2.event_set_status;const unsigned int mpp_flags = m->top.c2.fast_io
@@ -380,10 +381,11 @@/* Incoming data on UDP port */ else if (status & SOCKET_READ) { -read_incoming_link (&m->top, m->top.c2.link_socket); +read_incoming_link (&m->top, sock);if (!IS_SIG (&m->top)) { -multi_process_incoming_link (m,NULL , mpp_flags); +multi_process_incoming_link (m,NULL , mpp_flags, + sock); } }/* Incoming data on TUN device */
@@ -514,7 +516,11 @@else {/* process I/O */ -multi_process_io_udp (&multi); + +/* Since there's only one link_socket just use the first, in an upcoming +* patch this will be changed by using the link_socket returned by the +* event set */ +multi_process_io_udp (&multi, top->c2.link_sockets[0 ]);MULTI_CHECK_SIG (&multi); }
src/openvpn/mudp.h +4 -2
@@ -55,12 +55,14 @@* it. If no entry exists, this function handles its creation, and if * successful, returns the newly created instance. * -* @param m - The single multi_context structure. +* @param m - The single multi_context structure. +* @param ls - Listening socket where this instance is connecting to * * @return A pointer to a multi_instance if one already existed for the * packet's source address or if one was a newly created successfully. * NULL if one did not yet exist and a new one was not created. */ -struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated); +struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls);#endif /* ifndef MUDP_H */
src/openvpn/multi.c +14 -10
@@ -750,7 +750,8 @@* Create a client instance object for a newly connected client. */ struct multi_instance * -multi_create_instance (struct multi_context *m,const struct mroute_addr *real) +multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct multi_instance *mi;
@@ -773,7 +774,7 @@generate_prefix (mi); } -inherit_context_child (&mi->context, &m->top); +inherit_context_child (&mi->context, &m->top, ls);if (IS_SIG (&mi->context)) { goto err;
@@ -3124,7 +3125,8 @@ }void -multi_process_float (struct multi_context *m,struct multi_instance *mi) +multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls) {struct mroute_addr real = {0 };struct hash *hash = m->hash;
@@ -3180,8 +3182,8 @@ mi->context.c2.to_link_addr = &mi->context.c2.from;/* inherit parent link_socket and link_socket_info */ - mi->context.c2.link_socket = m->top.c2.link_socket; - mi->context.c2.link_socket_info->lsa->actual = m->top.c2.from; + mi->context.c2.link_sockets[0 ] = ls; + mi->context.c2.link_socket_infos[0 ]->lsa->actual = m->top.c2.from;tls_update_remote_addr (mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3329,7 +3331,8 @@* i.e. client -> server direction. */ bool -multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags) +multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls) {struct gc_arena gc =gc_new ();
@@ -3350,7 +3353,7 @@#ifdef MULTI_DEBUG_EVENT_LOOP printf ("TCP/UDP -> TUN [%d]\n" ,BLEN (&m->top.c2.buf));#endif -multi_set_pending (m,multi_get_create_instance_udp (m, &floated)); +multi_set_pending (m,multi_get_create_instance_udp (m, &floated, ls)); }else {
@@ -3391,7 +3394,7 @@/* nonzero length means that we have a valid, decrypted packed */ if (floated && c->c2.buf.len >0 ) { -multi_process_float (m, m->pending); +multi_process_float (m, m->pending, ls); }process_incoming_link_part2 (c, lsi, orig_buf);
@@ -3610,7 +3613,7 @@ }/* encrypt in instance context */ -process_incoming_tun (c); +process_incoming_tun (c, c->c2.link_sockets[0 ]);/* postprocess and set wakeup */ ret =multi_process_post (m, m->pending, mpp_flags);
@@ -3642,7 +3645,8 @@ { pip_flags |=PIP_MSSFIX ; } -process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf); +process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf, + item.instance->context.c2.link_sockets[0 ]);encrypt_sign (&item.instance->context, true);mbuf_free_buf (item.buffer);
src/openvpn/multi.h +9 -5
@@ -274,7 +274,8 @@void multi_top_free (struct multi_context *m); -struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real); +struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls);void multi_close_instance (struct multi_context *m,struct multi_instance *mi,bool shutdown);
@@ -288,7 +289,8 @@* existing peer. Updates multi_instance with new address, * updates hashtables in multi_context. */ -void multi_process_float (struct multi_context *m,struct multi_instance *mi); +void multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls);#define MPP_PRE_SELECT (1<<0)#define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -353,8 +355,10 @@* when using TCP transport. Otherwise NULL, as is * the case when using UDP transport. * @param mpp_flags - Fast I/O optimization flags. +* @param ls - Socket where the packet was received. */ -bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags); +bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls);/**
@@ -668,7 +672,7 @@#endif set_prefix (mi);vlan_process_outgoing_tun (m, mi); -process_outgoing_tun (&mi->context); +process_outgoing_tun (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
@@ -683,7 +687,7 @@ {bool ret = true;set_prefix (mi); -process_outgoing_link (&mi->context, mi->context.c2.link_socket); +process_outgoing_link (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
src/openvpn/openvpn.c +1 -1
@@ -91,7 +91,7 @@ }/* process the I/O which triggered select */ -process_io (c, c->c2.link_socket); +process_io (c, c->c2.link_sockets[0 ]);P2P_CHECK_SIG ();perf_pop ();
src/openvpn/openvpn.h +5 -4
@@ -154,7 +154,8 @@*/ struct context_1 { -struct link_socket_addr link_socket_addr; +int link_sockets_num; +struct link_socket_addr *link_socket_addrs;/**< Local and remote addresses on the * external network. */
@@ -233,11 +234,11 @@/* bitmask for event status. Check event.h for possible values */ unsigned int event_set_status; -struct link_socket *link_socket;/* socket used for TCP/UDP connection to remote */ +struct link_socket **link_sockets; +struct link_socket_info **link_socket_infos; +bool link_socket_owned; -/** This variable is used instead link_socket->info for P2MP UDP childs */ -struct link_socket_info *link_socket_info;const struct link_socket *accept_from;/* possibly do accept() on a parent link_socket */ struct link_socket_actual *to_link_addr;/* IP address of remote */
src/openvpn/ping.h +1 -1
@@ -63,7 +63,7 @@ && event_timeout_trigger(&c->c2.ping_rec_interval, &c->c2.timeval, (!c->options.ping_timer_remote - || link_socket_actual_defined(&c->c1.link_socket_addr.actual)) + || link_socket_actual_defined(&c->c1.link_socket_addrs[0].actual)) ? ETT_DEFAULT : 15)) {trigger_ping_timeout_signal (c);
src/openvpn/socket.c +34 -23
153 lines not on this page · raw message
src/openvpn/socket.h +12 -7
@@ -344,9 +344,13 @@/* * Initialize link_socket object. */ -void link_socket_init_phase1 (struct context *c,int mode); +void +link_socket_init_phase1 (struct context *c, +int sock_index, +int mode); -void link_socket_init_phase2 (struct context *c); +void link_socket_init_phase2 (struct context *c, +struct link_socket *sock);void do_preresolve (struct context *c);
@@ -1228,11 +1232,12 @@* Socket I/O wait functions */ -static inline bool -socket_read_residual (const struct link_socket *sock) -{ -return sock && sock->stream_buf.residual_fully_formed; -} +/* +* Extends the pre-existing read residual logic +* to all initialized sockets, ensuring the complete +* packet is read. +*/ +bool sockets_read_residual (const struct context *c);static inline event_t socket_event_handle (const struct link_socket *sock)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 9
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, ordex, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Patch Set 10: Code-Review-2
(18 comments)
Patchset:
PS10:
Getting there, and except for the bind_dev these are minor nitpicks in the source (but worth fixing if we do another round anyway).
In the review, I seem to have overlooked something, though - applying this on top of current master breaks --fragment servers - on the first connecting client, *boom*
```
2024-12-29 23:34:56 us=142019 Initialization Sequence Completed
2024-12-29 23:35:05 us=857683 Connection Attempt MULTI: multi_create_instance called
2024-12-29 23:35:05 us=857852 2001:608:0:814::f000:21 Re-using SSL/TLS context
2024-12-29 23:35:05 us=857903 2001:608:0:814::f000:21 WARNING: if you use --mssfix and --fragment, you should use the "mtu" flag for both or none of of them.
2024-12-29 23:35:05 us=858101 2001:608:0:814::f000:21 Control Channel MTU parms [ mss_fix:0 max_frag:0 tun_mtu:1250 tun_max_mtu:0 headroom:126 payload:1600 tailroom:126 ET:0 ]
Program received signal SIGSEGV, Segmentation fault.
0x000055555558121e in get_link_socket_info (c=0x5555556c6450)
at /home/gert/t_server.git/src/openvpn/forward.h:324
324 return &c->c2.link_sockets[0]->info;
(gdb) where
#0 0x000055555558121e in get_link_socket_info (c=0x5555556c6450)
at /home/gert/t_server.git/src/openvpn/forward.h:324
#1 do_init_fragment (c=0x5555556c6450) at init.c:3801
#2 init_instance ([email protected]...=0x5555556c6450, env=<optimized out>,
[email protected]...=10) at init.c:4736
#3 0x0000555555581e91 in inherit_context_child (
[email protected]...=0x5555556c6450, [email protected]...=0x7fffffffc848,
[email protected]...=0x55555569fb00) at init.c:4977
#4 0x00005555555999e0 in multi_create_instance ([email protected]...=0x7fffffffc780,
[email protected]...=0x7fffffffc3c0, [email protected]...=0x55555569fb00) at multi.c:777
#5 0x00005555555928b2 in multi_get_create_instance_udp (m=0x7fffffffc780,
[email protected]...=0x7fffffffc6cf, [email protected]...=0x55555569fb00)
at mudp.c:260
#6 0x000055555559a4dd in multi_process_incoming_link (
[email protected]...=0x7fffffffc780, [email protected]...=0x0,
[email protected]...=5, [email protected]...=0x55555569fb00) at multi.c:3356
#7 0x00005555555935f2 in multi_process_io_udp (m=0x7fffffffc780,
sock=0x55555569fb00) at mudp.c:387
#8 tunnel_server_udp ([email protected]...=0x7fffffffda10) at mudp.c:523
#9 0x000055555559b2c4 in tunnel_server ([email protected]...=0x7fffffffda10)
at multi.c:4168
(gdb) print &c->c2.link_sockets[0]->info
Cannot access memory at address 0x0
(gdb) print &c->c2.link_sockets[0]
$1 = (struct link_socket **) 0x0
```so it definitely looks like "socket not initialized", though I have no idea why.
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/721e4eca_fe894283 :
PS9, Line 4054: {
The if() should be outside and the for() inside - the condition does not depend on i.
http://gerrit.openvpn.net/c/openvpn/+/434/comment/1a384971_29102103 :
PS9, Line 4062: {
same thing.
http://gerrit.openvpn.net/c/openvpn/+/434/comment/89309b77_8f3abbb8 :
PS9, Line 4786: get_link_socket_info(c));
Should this be a per-socket thing? IPv4 vs. IPv6 will change overhead so the frame calculation will be wrong for all sockets != 0.
Maybe a comment to that extent ("for multiple listening sockets, this will not be correct for these cases, but everything but TLS should no longer be used anyway")?
http://gerrit.openvpn.net/c/openvpn/+/434/comment/a405a93a_e360204a :
PS9, Line 4991: &dest->gc);
if line length permits, can this be unwrapped?
File src/openvpn/mtcp.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/040f4e94_88362f91 :
PS9, Line 271: &c->c2.link_sockets[i]->ev_arg);
the diff looks as if there are tabs at the beginning of this line?
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/0490e7ea_822b07fb :
PS9, Line 388: sock);
please unwrap
File src/openvpn/multi.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/7963d5d0_1f026e7c :
PS9, Line 3336: {
I think this could be wrapped before const unsigned int mpp_flags
File src/openvpn/socket.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/c450a732_4bec3d43 :
PS9, Line 1037:
another blank line
http://gerrit.openvpn.net/c/openvpn/+/434/comment/a223f45e_43302346 :
PS9, Line 1875: sock->bind_dev = o->bind_dev;
where did that go to? another rebase accident? *red flag*
http://gerrit.openvpn.net/c/openvpn/+/434/comment/03786af0_25ca4cba :
PS9, Line 1019: socket_descriptor_t sd;
we shouldn't delete blank lines unrelated to actual changes (minor nit)
http://gerrit.openvpn.net/c/openvpn/+/434/comment/9c9ce7e2_01384c14 :
PS9, Line 1854: int mode)
please unwrap
http://gerrit.openvpn.net/c/openvpn/+/434/comment/b9a7826e_aead3ffe :
PS9, Line 1863: sock->remote_port = o->ce.remote_port;
not sure this change (remove the local variables remote_host and remote_port) is a good thing as part of this patchset. It's cleanup/refactoring, and unrelated, but makes this diff larger than it should be.
So I'd prefer to not do this set of changes.
http://gerrit.openvpn.net/c/openvpn/+/434/comment/bff14e2e_61aafce1 :
PS9, Line 1919: sock->proxy_dest_port = o->ce.remote_port;
this
http://gerrit.openvpn.net/c/openvpn/+/434/comment/ac638e3f_3c683fd8 :
PS9, Line 1924:
spurious blank line
http://gerrit.openvpn.net/c/openvpn/+/434/comment/8bdd62db_a3c5abdd :
PS9, Line 1931: sock->proxy_dest_port = o->ce.remote_port;
this
http://gerrit.openvpn.net/c/openvpn/+/434/comment/c27c8614_67874b24 :
PS9, Line 1936: sock->remote_port = o->ce.remote_port;
and this
http://gerrit.openvpn.net/c/openvpn/+/434/comment/731d7cd9_eba0b68a :
PS9, Line 2301: /* Always restore the saved signal --register/throw_signal will handle priority */
you lost a ` here after -- (this is not a command line option --register`)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 10
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Sun, 29 Dec 2024 22:40:09 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, ordex, plaisthos.
its_Giaan has uploaded a new patch set (#11) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Adapt socket handling to support listening on multiple sockets
Introduce internal changes preparing the server to handle multiple sockets concurrently for both TCP and UDP protocols. While no user-visible features are implemented yet, these modifications are essential for enabling future functionality such as listening on multiple ports.
Key changes are: converting link_socket from a single pointer to an array in various contexts, in order to be able to store multiple sockets at once.
---
M src/openvpn/dco.c
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mss.c
M src/openvpn/mtcp.c
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/openvpn.c
M src/openvpn/openvpn.h
M src/openvpn/ping.h
M src/openvpn/socket.c
M src/openvpn/socket.h
16 files changed, 326 insertions(+), 183 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/34/434/11
src/openvpn/dco.c +9 -9
@@ -478,11 +478,11 @@return 0 ; } -struct link_socket *ls = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[0 ]; -ASSERT (ls->info.connection_established); +ASSERT (sock->info.connection_established); -struct sockaddr *remoteaddr = &ls->info.lsa->actual.dest.addr.sa; +struct sockaddr *remoteaddr = &sock->info.lsa->actual.dest.addr.sa;struct tls_multi *multi = c->c2.tls_multi;#ifdef TARGET_FREEBSD /* In Linux in P2P mode the kernel automatically removes an existing peer
@@ -494,7 +494,7 @@ }#endif int ret =dco_new_peer (&c->c1.tuntap->dco, multi->peer_id, - c->c2.link_socket->sd,NULL , remoteaddr,NULL ,NULL ); + c->c2.link_sockets[0 ]->sd,NULL , remoteaddr,NULL ,NULL );if (ret <0 ) {return ret;
@@ -527,12 +527,12 @@#if ENABLE_IP_PKTINFO struct context *c = &mi->context; -if (!proto_is_udp (c->c2.link_socket->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) +if (!proto_is_udp (c->c2.link_sockets[0 ]->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) {return false; } -struct link_socket_actual *actual = &c->c2.link_socket_info->lsa->actual; +struct link_socket_actual *actual = &c->c2.link_socket_infos[0 ]->lsa->actual;switch (actual->dest.addr.sa.sa_family) {
@@ -577,7 +577,7 @@int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 }; -int sd = c->c2.link_socket->sd; +int sd = c->c2.link_sockets[0 ]->sd;if (c->mode ==CM_CHILD_TCP )
@@ -587,8 +587,8 @@ }else { -ASSERT (c->c2.link_socket_info->connection_established); - remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; +ASSERT (c->c2.link_socket_infos[0 ]->connection_established); + remoteaddr = &c->c2.link_socket_infos[0 ]->lsa->actual.dest.addr.sa; }/* In server mode we need to fetch the remote addresses from the push config */
src/openvpn/forward.c +29 -18
134 lines not on this page · raw message
src/openvpn/forward.h +14 -10
@@ -231,10 +231,12 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with the -* packet. +* @param c The context structure of the VPN tunnel associated with +* the packet. +* @param out_sock Socket that will be used to send out the packet. +* */ -void process_incoming_tun (struct context *c); +void process_incoming_tun (struct context *c,struct link_socket *out_sock);/**
@@ -246,10 +248,11 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with -* the packet. +* @param c The context structure of the VPN tunnel associated +* with the packet. +* @param in_sock Socket where the packet was received. */ -void process_outgoing_tun (struct context *c); +void process_outgoing_tun (struct context *c,struct link_socket *in_sock);/**************************************************************************/
@@ -304,20 +307,21 @@#define PIPV6_ICMP_NOHOST_SERVER (1<<6) -void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf); +void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf, +struct link_socket *sock);bool schedule_exit (struct context *c);static inline struct link_socket_info *get_link_socket_info (struct context *c) { -if (c->c2.link_socket_info) +if (c->c2.link_socket_infos) { -return c->c2.link_socket_info; +return c->c2.link_socket_infos[0 ]; }else { -return &c->c2.link_socket->info; +return &c->c2.link_sockets[0 ]->info; } }
src/openvpn/init.c +157 -78
428 lines not on this page · raw message
src/openvpn/init.h +2 -1
@@ -95,7 +95,8 @@bool do_deferred_options (struct context *c,const unsigned int found);void inherit_context_child (struct context *dest, -const struct context *src); +const struct context *src, +struct link_socket *ls);void inherit_context_top (struct context *dest,const struct context *src);
src/openvpn/mss.c +1 -1
@@ -357,7 +357,7 @@struct link_socket_info *lsi =get_link_socket_info (c);struct options *o = &c->options; -int pmtu = c->c2.link_socket->mtu; +int pmtu = c->c2.link_sockets[0 ]->mtu;sa_family_t af = lsi->lsa->actual.dest.addr.sa.sa_family;int proto = lsi->proto;
src/openvpn/mtcp.c +34 -20
114 lines not on this page · raw message
src/openvpn/mudp.c +12 -7
@@ -185,7 +185,8 @@*/ struct multi_instance * -multi_get_create_instance_udp (struct multi_context *m,bool *floated) +multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct mroute_addr real = {0 };
@@ -256,7 +257,7 @@* connect-freq but not against connect-freq-initial */ reflect_filter_rate_limit_decrease (m->initial_rate_limiter); - mi =multi_create_instance (m, &real); + mi =multi_create_instance (m, &real, ls);if (mi) {hash_add_fast (hash, bucket, &mi->real, hv, mi);
@@ -317,7 +318,7 @@msg_set_prefix ("Connection Attempt" ); m->top.c2.to_link = m->hmac_reply; m->top.c2.to_link_addr = m->hmac_reply_dest; -process_outgoing_link (&m->top, m->top.c2.link_socket); +process_outgoing_link (&m->top, m->top.c2.link_sockets[0 ]); m->hmac_reply_dest =NULL ; } }
@@ -326,7 +327,7 @@* Process an I/O event. */ static void -multi_process_io_udp (struct multi_context *m) +multi_process_io_udp (struct multi_context *m,struct link_socket *sock) {const unsigned int status = m->top.c2.event_set_status;const unsigned int mpp_flags = m->top.c2.fast_io
@@ -380,10 +381,10 @@/* Incoming data on UDP port */ else if (status & SOCKET_READ) { -read_incoming_link (&m->top, m->top.c2.link_socket); +read_incoming_link (&m->top, sock);if (!IS_SIG (&m->top)) { -multi_process_incoming_link (m,NULL , mpp_flags); +multi_process_incoming_link (m,NULL , mpp_flags, sock); } }/* Incoming data on TUN device */
@@ -514,7 +515,11 @@else {/* process I/O */ -multi_process_io_udp (&multi); + +/* Since there's only one link_socket just use the first, in an upcoming +* patch this will be changed by using the link_socket returned by the +* event set */ +multi_process_io_udp (&multi, top->c2.link_sockets[0 ]);MULTI_CHECK_SIG (&multi); }
src/openvpn/mudp.h +4 -2
@@ -55,12 +55,14 @@* it. If no entry exists, this function handles its creation, and if * successful, returns the newly created instance. * -* @param m - The single multi_context structure. +* @param m - The single multi_context structure. +* @param ls - Listening socket where this instance is connecting to * * @return A pointer to a multi_instance if one already existed for the * packet's source address or if one was a newly created successfully. * NULL if one did not yet exist and a new one was not created. */ -struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated); +struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls);#endif /* ifndef MUDP_H */
src/openvpn/multi.c +14 -10
@@ -750,7 +750,8 @@* Create a client instance object for a newly connected client. */ struct multi_instance * -multi_create_instance (struct multi_context *m,const struct mroute_addr *real) +multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct multi_instance *mi;
@@ -773,7 +774,7 @@generate_prefix (mi); } -inherit_context_child (&mi->context, &m->top); +inherit_context_child (&mi->context, &m->top, ls);if (IS_SIG (&mi->context)) { goto err;
@@ -3124,7 +3125,8 @@ }void -multi_process_float (struct multi_context *m,struct multi_instance *mi) +multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls) {struct mroute_addr real = {0 };struct hash *hash = m->hash;
@@ -3180,8 +3182,8 @@ mi->context.c2.to_link_addr = &mi->context.c2.from;/* inherit parent link_socket and link_socket_info */ - mi->context.c2.link_socket = m->top.c2.link_socket; - mi->context.c2.link_socket_info->lsa->actual = m->top.c2.from; + mi->context.c2.link_sockets[0 ] = ls; + mi->context.c2.link_socket_infos[0 ]->lsa->actual = m->top.c2.from;tls_update_remote_addr (mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3329,7 +3331,8 @@* i.e. client -> server direction. */ bool -multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags) +multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance, +const unsigned int mpp_flags,struct link_socket *ls) {struct gc_arena gc =gc_new ();
@@ -3350,7 +3353,7 @@#ifdef MULTI_DEBUG_EVENT_LOOP printf ("TCP/UDP -> TUN [%d]\n" ,BLEN (&m->top.c2.buf));#endif -multi_set_pending (m,multi_get_create_instance_udp (m, &floated)); +multi_set_pending (m,multi_get_create_instance_udp (m, &floated, ls)); }else {
@@ -3391,7 +3394,7 @@/* nonzero length means that we have a valid, decrypted packed */ if (floated && c->c2.buf.len >0 ) { -multi_process_float (m, m->pending); +multi_process_float (m, m->pending, ls); }process_incoming_link_part2 (c, lsi, orig_buf);
@@ -3610,7 +3613,7 @@ }/* encrypt in instance context */ -process_incoming_tun (c); +process_incoming_tun (c, c->c2.link_sockets[0 ]);/* postprocess and set wakeup */ ret =multi_process_post (m, m->pending, mpp_flags);
@@ -3642,7 +3645,8 @@ { pip_flags |=PIP_MSSFIX ; } -process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf); +process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf, + item.instance->context.c2.link_sockets[0 ]);encrypt_sign (&item.instance->context, true);mbuf_free_buf (item.buffer);
src/openvpn/multi.h +9 -5
@@ -275,7 +275,8 @@void multi_top_free (struct multi_context *m); -struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real); +struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls);void multi_close_instance (struct multi_context *m,struct multi_instance *mi,bool shutdown);
@@ -289,7 +290,8 @@* existing peer. Updates multi_instance with new address, * updates hashtables in multi_context. */ -void multi_process_float (struct multi_context *m,struct multi_instance *mi); +void multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls);#define MPP_PRE_SELECT (1<<0)#define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -354,8 +356,10 @@* when using TCP transport. Otherwise NULL, as is * the case when using UDP transport. * @param mpp_flags - Fast I/O optimization flags. +* @param ls - Socket where the packet was received. */ -bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags); +bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls);/**
@@ -669,7 +673,7 @@#endif set_prefix (mi);vlan_process_outgoing_tun (m, mi); -process_outgoing_tun (&mi->context); +process_outgoing_tun (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
@@ -684,7 +688,7 @@ {bool ret = true;set_prefix (mi); -process_outgoing_link (&mi->context, mi->context.c2.link_socket); +process_outgoing_link (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
src/openvpn/openvpn.c +1 -1
@@ -91,7 +91,7 @@ }/* process the I/O which triggered select */ -process_io (c, c->c2.link_socket); +process_io (c, c->c2.link_sockets[0 ]);P2P_CHECK_SIG ();perf_pop ();
src/openvpn/openvpn.h +5 -4
@@ -154,7 +154,8 @@*/ struct context_1 { -struct link_socket_addr link_socket_addr; +int link_sockets_num; +struct link_socket_addr *link_socket_addrs;/**< Local and remote addresses on the * external network. */
@@ -233,11 +234,11 @@/* bitmask for event status. Check event.h for possible values */ unsigned int event_set_status; -struct link_socket *link_socket;/* socket used for TCP/UDP connection to remote */ +struct link_socket **link_sockets; +struct link_socket_info **link_socket_infos; +bool link_socket_owned; -/** This variable is used instead link_socket->info for P2MP UDP childs */ -struct link_socket_info *link_socket_info;const struct link_socket *accept_from;/* possibly do accept() on a parent link_socket */ struct link_socket_actual *to_link_addr;/* IP address of remote */
src/openvpn/ping.h +1 -1
@@ -63,7 +63,7 @@ && event_timeout_trigger(&c->c2.ping_rec_interval, &c->c2.timeval, (!c->options.ping_timer_remote - || link_socket_actual_defined(&c->c1.link_socket_addr.actual)) + || link_socket_actual_defined(&c->c1.link_socket_addrs[0].actual)) ? ETT_DEFAULT : 15)) {trigger_ping_timeout_signal (c);
src/openvpn/socket.c +22 -9
@@ -42,6 +42,21 @@#include "memdbg.h" +bool +sockets_read_residual (const struct context *c) +{ +int i; + +for (i =0 ; i < c->c1.link_sockets_num; i++) + { +if (c->c2.link_sockets[i]->stream_buf.residual_fully_formed) + { +return true; + } + } +return false; +} +/* * Convert sockflags/getaddr_flags into getaddr_flags */
@@ -1454,7 +1469,6 @@#ifdef TARGET_ANDROID protect_fd_nonlocal (sd, remote);#endif -set_nonblock (sd); status =connect (sd, remote,af_addr_size (remote->sa_family));if (status)
@@ -1851,9 +1865,9 @@ }void -link_socket_init_phase1 (struct context *c,int mode) +link_socket_init_phase1 (struct context *c,int sock_index,int mode) { -struct link_socket *sock = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[sock_index];struct options *o = &c->options;ASSERT (sock);
@@ -1879,19 +1893,20 @@ sock->socket_buffer_sizes.sndbuf = o->sndbuf; sock->sockflags = o->sockflags; +#if PORT_SHARE if (o->port_share_host && o->port_share_port) { sock->sockflags |=SF_PORT_SHARE ; }#endif + sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; - sock->info.lsa = &c->c1.link_socket_addr; + sock->info.lsa = &c->c1.link_socket_addrs[sock_index]; sock->info.bind_ipv6_only = o->ce.bind_ipv6_only; sock->info.ipchange_command = o->ipchange; sock->info.plugins = c->plugins;
@@ -2186,9 +2201,9 @@/* finalize socket initialization */ void -link_socket_init_phase2 (struct context *c) +link_socket_init_phase2 (struct context *c, +struct link_socket *sock) { -struct link_socket *sock = c->c2.link_socket;const struct frame *frame = &c->c2.frame;struct signal_info *sig_info = c->sig;
@@ -2234,7 +2249,6 @@ {create_socket (sock, sock->info.lsa->current_remote); } - }/* If socket has not already been created create it now */
@@ -2253,7 +2267,6 @@ addr_family_name(sock->info.lsa->bind_local->ai_family)); sock->info.af = sock->info.lsa->bind_local->ai_family; } -create_socket (sock, sock->info.lsa->bind_local); } }
src/openvpn/socket.h +12 -7
@@ -344,9 +344,13 @@/* * Initialize link_socket object. */ -void link_socket_init_phase1 (struct context *c,int mode); +void +link_socket_init_phase1 (struct context *c, +int sock_index, +int mode); -void link_socket_init_phase2 (struct context *c); +void link_socket_init_phase2 (struct context *c, +struct link_socket *sock);void do_preresolve (struct context *c);
@@ -1228,11 +1232,12 @@* Socket I/O wait functions */ -static inline bool -socket_read_residual (const struct link_socket *sock) -{ -return sock && sock->stream_buf.residual_fully_formed; -} +/* +* Extends the pre-existing read residual logic +* to all initialized sockets, ensuring the complete +* packet is read. +*/ +bool sockets_read_residual (const struct context *c);static inline event_t socket_event_handle (const struct link_socket *sock)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 11
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveAttention is currently required from: cron2, ordex, plaisthos.
its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Patch Set 10:
(17 comments)
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/69eb0e47_7a2fefdf :
PS9, Line 4054: {
Quoted 1 line
The
if()should be outside and thefor()inside - the condition does not depend oni.
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/dff8a59a_21679821 :
PS9, Line 4062: {
Quoted 1 line
same thing.
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/c947a2ab_76ea9aa3 :
PS9, Line 4786: get_link_socket_info(c));
Quoted 1 line
Should this be a per-socket thing? IPv4 vs. […]
Made this a per-socket thing.
http://gerrit.openvpn.net/c/openvpn/+/434/comment/b147968f_4b23f49c :
PS9, Line 4991: &dest->gc);
Quoted 1 line
if line length permits, can this be unwrapped?
Done
File src/openvpn/mtcp.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/45b85b7d_90856afd :
PS9, Line 271: &c->c2.link_sockets[i]->ev_arg);
Quoted 1 line
the diff looks as if there are tabs at the beginning of this line?
Done
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/e1854ff0_37af4d92 :
PS9, Line 388: sock);
Quoted 1 line
please unwrap
Done
File src/openvpn/multi.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/a8787998_d8ad16d6 :
PS9, Line 3336: {
Quoted 1 line
I think this could be wrapped before
const unsigned int mpp_flags
Done
File src/openvpn/socket.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/9a778853_9ea799d9 :
PS9, Line 1037:
Quoted 1 line
another blank line
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/55bd01b2_52c753e9 :
PS9, Line 1875: sock->bind_dev = o->bind_dev;
Quoted 1 line
where did that go to? another rebase accident? *red flag*
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/6094ee4a_ac948ea1 :
PS9, Line 1019: socket_descriptor_t sd;
Quoted 1 line
we shouldn't delete blank lines unrelated to actual changes (minor nit)
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/e87a08aa_1f6e0dab :
PS9, Line 1854: int mode)
Quoted 1 line
please unwrap
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/36576466_961a732f :
PS9, Line 1863: sock->remote_port = o->ce.remote_port;
Quoted 1 line
not sure this change (remove the local variables
remote_hostandremote_port) is a good thing as […]
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/9434c644_f418ccd8 :
PS9, Line 1919: sock->proxy_dest_port = o->ce.remote_port;
Quoted 1 line
this
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/f14a026f_c6ca2521 :
PS9, Line 1924:
Quoted 1 line
spurious blank line
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/8c99342c_c4d10f9f :
PS9, Line 1931: sock->proxy_dest_port = o->ce.remote_port;
Quoted 1 line
this
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/15fb1903_d0b82fdd :
PS9, Line 1936: sock->remote_port = o->ce.remote_port;
Quoted 1 line
and this
Done
http://gerrit.openvpn.net/c/openvpn/+/434/comment/066facc3_d851126b :
PS9, Line 2301: /* Always restore the saved signal --register/throw_signal will handle priority */
Quoted 1 line
you lost a `
here after--(this is not a command line option--register`)
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 10
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Mon, 30 Dec 2024 13:37:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, ordex, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Patch Set 11: Code-Review+2
(2 comments)
Patchset:
PS11:
Seems we're getting there - with the changed ordering of blocks in init.c, everything seems well-initialized now, and it passes all the server side tests...
``` master... Test sets succeeded: 1 1a 1b 1c 1d 1e 1x 2 2a 2b 2c 2g 2h 2d 2e 2f 2w 2x 2y 2z1 2z2 3 3m 4 4a 4b 5 5a 5b 5c 5d 5e 5m 5n 5u1 5u2 5v1 5v2 5v3 5w1 5w2 5w3 5w4 5x1 5x2 5x3 5x4 6 7 7b 7l 7x 7x2 7y 8 8a 9 9a 10 10a 10b 10u 10v 10w 10x 10z 11 11a 11z 11 11a. Test sets failed: none. ```
this is a good achievement. We need more testing when the rest of the series is in, but at this point, I think all that can be done with this patch on its own is done.
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/7fc63e02_8cf6443f :
PS9, Line 4786: get_link_socket_info(c));
Quoted 1 line
Made this a per-socket thing.
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 11
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Mon, 30 Dec 2024 16:23:17 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: its_Giaan <[email protected]...>
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
PATCH v11 1/1 Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveFrom: Antonio Quartulli <[email protected]...>
Introduce internal changes preparing the server to handle multiple sockets concurrently for both TCP and UDP protocols. While no user-visible features are implemented yet, these modifications are essential for enabling future functionality such as listening on multiple ports.
Key changes are: converting link_socket from a single pointer to an array in various contexts, in order to be able to store multiple sockets at once.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/434
This mail reflects revision 11 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
src/openvpn/dco.c +9 -9
@@ -478,11 +478,11 @@return 0 ; } -struct link_socket *ls = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[0 ]; -ASSERT (ls->info.connection_established); +ASSERT (sock->info.connection_established); -struct sockaddr *remoteaddr = &ls->info.lsa->actual.dest.addr.sa; +struct sockaddr *remoteaddr = &sock->info.lsa->actual.dest.addr.sa;struct tls_multi *multi = c->c2.tls_multi;#ifdef TARGET_FREEBSD /* In Linux in P2P mode the kernel automatically removes an existing peer
@@ -494,7 +494,7 @@ }#endif int ret =dco_new_peer (&c->c1.tuntap->dco, multi->peer_id, - c->c2.link_socket->sd,NULL , remoteaddr,NULL ,NULL ); + c->c2.link_sockets[0 ]->sd,NULL , remoteaddr,NULL ,NULL );if (ret <0 ) {return ret;
@@ -527,12 +527,12 @@#if ENABLE_IP_PKTINFO struct context *c = &mi->context; -if (!proto_is_udp (c->c2.link_socket->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) +if (!proto_is_udp (c->c2.link_sockets[0 ]->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) {return false; } -struct link_socket_actual *actual = &c->c2.link_socket_info->lsa->actual; +struct link_socket_actual *actual = &c->c2.link_socket_infos[0 ]->lsa->actual;switch (actual->dest.addr.sa.sa_family) {
@@ -577,7 +577,7 @@int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 }; -int sd = c->c2.link_socket->sd; +int sd = c->c2.link_sockets[0 ]->sd;if (c->mode ==CM_CHILD_TCP )
@@ -587,8 +587,8 @@ }else { -ASSERT (c->c2.link_socket_info->connection_established); - remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; +ASSERT (c->c2.link_socket_infos[0 ]->connection_established); + remoteaddr = &c->c2.link_socket_infos[0 ]->lsa->actual.dest.addr.sa; }/* In server mode we need to fetch the remote addresses from the push config */
src/openvpn/forward.c +29 -18
134 lines not on this page · raw message
src/openvpn/forward.h +14 -10
@@ -231,10 +231,12 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with the -* packet. +* @param c The context structure of the VPN tunnel associated with +* the packet. +* @param out_sock Socket that will be used to send out the packet. +* */ -void process_incoming_tun (struct context *c); +void process_incoming_tun (struct context *c,struct link_socket *out_sock);/**
@@ -246,10 +248,11 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with -* the packet. +* @param c The context structure of the VPN tunnel associated +* with the packet. +* @param in_sock Socket where the packet was received. */ -void process_outgoing_tun (struct context *c); +void process_outgoing_tun (struct context *c,struct link_socket *in_sock);/**************************************************************************/
@@ -304,20 +307,21 @@#define PIPV6_ICMP_NOHOST_SERVER (1<<6) -void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf); +void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf, +struct link_socket *sock);bool schedule_exit (struct context *c);static inline struct link_socket_info *get_link_socket_info (struct context *c) { -if (c->c2.link_socket_info) +if (c->c2.link_socket_infos) { -return c->c2.link_socket_info; +return c->c2.link_socket_infos[0 ]; }else { -return &c->c2.link_socket->info; +return &c->c2.link_sockets[0 ]->info; } }
src/openvpn/init.c +157 -78
428 lines not on this page · raw message
src/openvpn/init.h +2 -1
@@ -95,7 +95,8 @@bool do_deferred_options (struct context *c,const unsigned int found);void inherit_context_child (struct context *dest, -const struct context *src); +const struct context *src, +struct link_socket *ls);void inherit_context_top (struct context *dest,const struct context *src);
src/openvpn/mss.c +1 -1
@@ -357,7 +357,7 @@struct link_socket_info *lsi =get_link_socket_info (c);struct options *o = &c->options; -int pmtu = c->c2.link_socket->mtu; +int pmtu = c->c2.link_sockets[0 ]->mtu;sa_family_t af = lsi->lsa->actual.dest.addr.sa.sa_family;int proto = lsi->proto;
src/openvpn/mtcp.c +34 -20
114 lines not on this page · raw message
src/openvpn/mudp.c +12 -7
@@ -185,7 +185,8 @@*/ struct multi_instance * -multi_get_create_instance_udp (struct multi_context *m,bool *floated) +multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct mroute_addr real = {0 };
@@ -256,7 +257,7 @@* connect-freq but not against connect-freq-initial */ reflect_filter_rate_limit_decrease (m->initial_rate_limiter); - mi =multi_create_instance (m, &real); + mi =multi_create_instance (m, &real, ls);if (mi) {hash_add_fast (hash, bucket, &mi->real, hv, mi);
@@ -317,7 +318,7 @@msg_set_prefix ("Connection Attempt" ); m->top.c2.to_link = m->hmac_reply; m->top.c2.to_link_addr = m->hmac_reply_dest; -process_outgoing_link (&m->top, m->top.c2.link_socket); +process_outgoing_link (&m->top, m->top.c2.link_sockets[0 ]); m->hmac_reply_dest =NULL ; } }
@@ -326,7 +327,7 @@* Process an I/O event. */ static void -multi_process_io_udp (struct multi_context *m) +multi_process_io_udp (struct multi_context *m,struct link_socket *sock) {const unsigned int status = m->top.c2.event_set_status;const unsigned int mpp_flags = m->top.c2.fast_io
@@ -380,10 +381,10 @@/* Incoming data on UDP port */ else if (status & SOCKET_READ) { -read_incoming_link (&m->top, m->top.c2.link_socket); +read_incoming_link (&m->top, sock);if (!IS_SIG (&m->top)) { -multi_process_incoming_link (m,NULL , mpp_flags); +multi_process_incoming_link (m,NULL , mpp_flags, sock); } }/* Incoming data on TUN device */
@@ -514,7 +515,11 @@else {/* process I/O */ -multi_process_io_udp (&multi); + +/* Since there's only one link_socket just use the first, in an upcoming +* patch this will be changed by using the link_socket returned by the +* event set */ +multi_process_io_udp (&multi, top->c2.link_sockets[0 ]);MULTI_CHECK_SIG (&multi); }
src/openvpn/mudp.h +4 -2
@@ -55,12 +55,14 @@* it. If no entry exists, this function handles its creation, and if * successful, returns the newly created instance. * -* @param m - The single multi_context structure. +* @param m - The single multi_context structure. +* @param ls - Listening socket where this instance is connecting to * * @return A pointer to a multi_instance if one already existed for the * packet's source address or if one was a newly created successfully. * NULL if one did not yet exist and a new one was not created. */ -struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated); +struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls);#endif /* ifndef MUDP_H */
src/openvpn/multi.c +14 -10
@@ -750,7 +750,8 @@* Create a client instance object for a newly connected client. */ struct multi_instance * -multi_create_instance (struct multi_context *m,const struct mroute_addr *real) +multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct multi_instance *mi;
@@ -773,7 +774,7 @@generate_prefix (mi); } -inherit_context_child (&mi->context, &m->top); +inherit_context_child (&mi->context, &m->top, ls);if (IS_SIG (&mi->context)) { goto err;
@@ -3124,7 +3125,8 @@ }void -multi_process_float (struct multi_context *m,struct multi_instance *mi) +multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls) {struct mroute_addr real = {0 };struct hash *hash = m->hash;
@@ -3180,8 +3182,8 @@ mi->context.c2.to_link_addr = &mi->context.c2.from;/* inherit parent link_socket and link_socket_info */ - mi->context.c2.link_socket = m->top.c2.link_socket; - mi->context.c2.link_socket_info->lsa->actual = m->top.c2.from; + mi->context.c2.link_sockets[0 ] = ls; + mi->context.c2.link_socket_infos[0 ]->lsa->actual = m->top.c2.from;tls_update_remote_addr (mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3329,7 +3331,8 @@* i.e. client -> server direction. */ bool -multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags) +multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance, +const unsigned int mpp_flags,struct link_socket *ls) {struct gc_arena gc =gc_new ();
@@ -3350,7 +3353,7 @@#ifdef MULTI_DEBUG_EVENT_LOOP printf ("TCP/UDP -> TUN [%d]\n" ,BLEN (&m->top.c2.buf));#endif -multi_set_pending (m,multi_get_create_instance_udp (m, &floated)); +multi_set_pending (m,multi_get_create_instance_udp (m, &floated, ls)); }else {
@@ -3391,7 +3394,7 @@/* nonzero length means that we have a valid, decrypted packed */ if (floated && c->c2.buf.len >0 ) { -multi_process_float (m, m->pending); +multi_process_float (m, m->pending, ls); }process_incoming_link_part2 (c, lsi, orig_buf);
@@ -3610,7 +3613,7 @@ }/* encrypt in instance context */ -process_incoming_tun (c); +process_incoming_tun (c, c->c2.link_sockets[0 ]);/* postprocess and set wakeup */ ret =multi_process_post (m, m->pending, mpp_flags);
@@ -3642,7 +3645,8 @@ { pip_flags |=PIP_MSSFIX ; } -process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf); +process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf, + item.instance->context.c2.link_sockets[0 ]);encrypt_sign (&item.instance->context, true);mbuf_free_buf (item.buffer);
src/openvpn/multi.h +9 -5
@@ -275,7 +275,8 @@void multi_top_free (struct multi_context *m); -struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real); +struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls);void multi_close_instance (struct multi_context *m,struct multi_instance *mi,bool shutdown);
@@ -289,7 +290,8 @@* existing peer. Updates multi_instance with new address, * updates hashtables in multi_context. */ -void multi_process_float (struct multi_context *m,struct multi_instance *mi); +void multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls);#define MPP_PRE_SELECT (1<<0)#define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -354,8 +356,10 @@* when using TCP transport. Otherwise NULL, as is * the case when using UDP transport. * @param mpp_flags - Fast I/O optimization flags. +* @param ls - Socket where the packet was received. */ -bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags); +bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls);/**
@@ -669,7 +673,7 @@#endif set_prefix (mi);vlan_process_outgoing_tun (m, mi); -process_outgoing_tun (&mi->context); +process_outgoing_tun (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
@@ -684,7 +688,7 @@ {bool ret = true;set_prefix (mi); -process_outgoing_link (&mi->context, mi->context.c2.link_socket); +process_outgoing_link (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
src/openvpn/openvpn.c +1 -1
@@ -91,7 +91,7 @@ }/* process the I/O which triggered select */ -process_io (c, c->c2.link_socket); +process_io (c, c->c2.link_sockets[0 ]);P2P_CHECK_SIG ();perf_pop ();
src/openvpn/openvpn.h +5 -4
@@ -154,7 +154,8 @@*/ struct context_1 { -struct link_socket_addr link_socket_addr; +int link_sockets_num; +struct link_socket_addr *link_socket_addrs;/**< Local and remote addresses on the * external network. */
@@ -233,11 +234,11 @@/* bitmask for event status. Check event.h for possible values */ unsigned int event_set_status; -struct link_socket *link_socket;/* socket used for TCP/UDP connection to remote */ +struct link_socket **link_sockets; +struct link_socket_info **link_socket_infos; +bool link_socket_owned; -/** This variable is used instead link_socket->info for P2MP UDP childs */ -struct link_socket_info *link_socket_info;const struct link_socket *accept_from;/* possibly do accept() on a parent link_socket */ struct link_socket_actual *to_link_addr;/* IP address of remote */
src/openvpn/ping.h +1 -1
@@ -63,7 +63,7 @@ && event_timeout_trigger(&c->c2.ping_rec_interval, &c->c2.timeval, (!c->options.ping_timer_remote - || link_socket_actual_defined(&c->c1.link_socket_addr.actual)) + || link_socket_actual_defined(&c->c1.link_socket_addrs[0].actual)) ? ETT_DEFAULT : 15)) {trigger_ping_timeout_signal (c);
src/openvpn/socket.c +22 -9
@@ -42,6 +42,21 @@#include "memdbg.h" +bool +sockets_read_residual (const struct context *c) +{ +int i; + +for (i =0 ; i < c->c1.link_sockets_num; i++) + { +if (c->c2.link_sockets[i]->stream_buf.residual_fully_formed) + { +return true; + } + } +return false; +} +/* * Convert sockflags/getaddr_flags into getaddr_flags */
@@ -1454,7 +1469,6 @@#ifdef TARGET_ANDROID protect_fd_nonlocal (sd, remote);#endif -set_nonblock (sd); status =connect (sd, remote,af_addr_size (remote->sa_family));if (status)
@@ -1851,9 +1865,9 @@ }void -link_socket_init_phase1 (struct context *c,int mode) +link_socket_init_phase1 (struct context *c,int sock_index,int mode) { -struct link_socket *sock = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[sock_index];struct options *o = &c->options;ASSERT (sock);
@@ -1879,19 +1893,20 @@ sock->socket_buffer_sizes.sndbuf = o->sndbuf; sock->sockflags = o->sockflags; +#if PORT_SHARE if (o->port_share_host && o->port_share_port) { sock->sockflags |=SF_PORT_SHARE ; }#endif + sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; - sock->info.lsa = &c->c1.link_socket_addr; + sock->info.lsa = &c->c1.link_socket_addrs[sock_index]; sock->info.bind_ipv6_only = o->ce.bind_ipv6_only; sock->info.ipchange_command = o->ipchange; sock->info.plugins = c->plugins;
@@ -2186,9 +2201,9 @@/* finalize socket initialization */ void -link_socket_init_phase2 (struct context *c) +link_socket_init_phase2 (struct context *c, +struct link_socket *sock) { -struct link_socket *sock = c->c2.link_socket;const struct frame *frame = &c->c2.frame;struct signal_info *sig_info = c->sig;
@@ -2234,7 +2249,6 @@ {create_socket (sock, sock->info.lsa->current_remote); } - }/* If socket has not already been created create it now */
@@ -2253,7 +2267,6 @@ addr_family_name(sock->info.lsa->bind_local->ai_family)); sock->info.af = sock->info.lsa->bind_local->ai_family; } -create_socket (sock, sock->info.lsa->bind_local); } }
src/openvpn/socket.h +12 -7
@@ -344,9 +344,13 @@/* * Initialize link_socket object. */ -void link_socket_init_phase1 (struct context *c,int mode); +void +link_socket_init_phase1 (struct context *c, +int sock_index, +int mode); -void link_socket_init_phase2 (struct context *c); +void link_socket_init_phase2 (struct context *c, +struct link_socket *sock);void do_preresolve (struct context *c);
@@ -1228,11 +1232,12 @@* Socket I/O wait functions */ -static inline bool -socket_read_residual (const struct link_socket *sock) -{ -return sock && sock->stream_buf.residual_fully_formed; -} +/* +* Extends the pre-existing read residual logic +* to all initialized sockets, ensuring the complete +* packet is read. +*/ +bool sockets_read_residual (const struct context *c);static inline event_t socket_event_handle (const struct link_socket *sock)
[Openvpn-devel] [PATCH applied] Re: Adapt socket handling to support listening on multiple sockets
Detailed discussion, review, etc. is all on gerrit (and linked in this thread). So not repeating all the details.
Stared at the code and the incremental patches long and hard, and gave it a thorough test on the client/server testbed (which broke on v10), but now it succeeds.
Your patch has been applied to the master branch.
commit 94b391d7ef5cb4cdac34a0d122fb9cbd11d82f75
Author: Antonio Quartulli Date: Mon Dec 30 17:23:37 2024 +0100
Adapt socket handling to support listening on multiple sockets
Signed-off-by: Antonio Quartulli <[email protected]...>
Signed-off-by: Gianmarco De Gregori <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30309.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, ordex, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Patch Set 11:
(1 comment)
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/434/comment/1ad9edae_4e128239 :
PS7, Line 384: for (int i = 0; i < m->top.c1.link_sockets_num; i++)
Quoted 1 line
In the next patches we will have a common server loop for both TCP and UDP however the I/O processin […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 11
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Mon, 30 Dec 2024 16:24:16 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: its_Giaan <[email protected]...>
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archivecron2 has uploaded a new patch set (#12) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by cron2
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Adapt socket handling to support listening on multiple sockets
Introduce internal changes preparing the server to handle multiple sockets concurrently for both TCP and UDP protocols. While no user-visible features are implemented yet, these modifications are essential for enabling future functionality such as listening on multiple ports.
Key changes are: converting link_socket from a single pointer to an array in various contexts, in order to be able to store multiple sockets at once.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30309.html
---
M src/openvpn/dco.c
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mss.c
M src/openvpn/mtcp.c
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/openvpn.c
M src/openvpn/openvpn.h
M src/openvpn/ping.h
M src/openvpn/socket.c
M src/openvpn/socket.h
16 files changed, 326 insertions(+), 183 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/34/434/12
src/openvpn/dco.c +9 -9
@@ -478,11 +478,11 @@return 0 ; } -struct link_socket *ls = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[0 ]; -ASSERT (ls->info.connection_established); +ASSERT (sock->info.connection_established); -struct sockaddr *remoteaddr = &ls->info.lsa->actual.dest.addr.sa; +struct sockaddr *remoteaddr = &sock->info.lsa->actual.dest.addr.sa;struct tls_multi *multi = c->c2.tls_multi;#ifdef TARGET_FREEBSD /* In Linux in P2P mode the kernel automatically removes an existing peer
@@ -494,7 +494,7 @@ }#endif int ret =dco_new_peer (&c->c1.tuntap->dco, multi->peer_id, - c->c2.link_socket->sd,NULL , remoteaddr,NULL ,NULL ); + c->c2.link_sockets[0 ]->sd,NULL , remoteaddr,NULL ,NULL );if (ret <0 ) {return ret;
@@ -527,12 +527,12 @@#if ENABLE_IP_PKTINFO struct context *c = &mi->context; -if (!proto_is_udp (c->c2.link_socket->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) +if (!proto_is_udp (c->c2.link_sockets[0 ]->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) {return false; } -struct link_socket_actual *actual = &c->c2.link_socket_info->lsa->actual; +struct link_socket_actual *actual = &c->c2.link_socket_infos[0 ]->lsa->actual;switch (actual->dest.addr.sa.sa_family) {
@@ -577,7 +577,7 @@int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 }; -int sd = c->c2.link_socket->sd; +int sd = c->c2.link_sockets[0 ]->sd;if (c->mode ==CM_CHILD_TCP )
@@ -587,8 +587,8 @@ }else { -ASSERT (c->c2.link_socket_info->connection_established); - remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; +ASSERT (c->c2.link_socket_infos[0 ]->connection_established); + remoteaddr = &c->c2.link_socket_infos[0 ]->lsa->actual.dest.addr.sa; }/* In server mode we need to fetch the remote addresses from the push config */
src/openvpn/forward.c +29 -18
134 lines not on this page · raw message
src/openvpn/forward.h +14 -10
@@ -231,10 +231,12 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with the -* packet. +* @param c The context structure of the VPN tunnel associated with +* the packet. +* @param out_sock Socket that will be used to send out the packet. +* */ -void process_incoming_tun (struct context *c); +void process_incoming_tun (struct context *c,struct link_socket *out_sock);/**
@@ -246,10 +248,11 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with -* the packet. +* @param c The context structure of the VPN tunnel associated +* with the packet. +* @param in_sock Socket where the packet was received. */ -void process_outgoing_tun (struct context *c); +void process_outgoing_tun (struct context *c,struct link_socket *in_sock);/**************************************************************************/
@@ -304,20 +307,21 @@#define PIPV6_ICMP_NOHOST_SERVER (1<<6) -void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf); +void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf, +struct link_socket *sock);bool schedule_exit (struct context *c);static inline struct link_socket_info *get_link_socket_info (struct context *c) { -if (c->c2.link_socket_info) +if (c->c2.link_socket_infos) { -return c->c2.link_socket_info; +return c->c2.link_socket_infos[0 ]; }else { -return &c->c2.link_socket->info; +return &c->c2.link_sockets[0 ]->info; } }
src/openvpn/init.c +157 -78
428 lines not on this page · raw message
src/openvpn/init.h +2 -1
@@ -95,7 +95,8 @@bool do_deferred_options (struct context *c,const unsigned int found);void inherit_context_child (struct context *dest, -const struct context *src); +const struct context *src, +struct link_socket *ls);void inherit_context_top (struct context *dest,const struct context *src);
src/openvpn/mss.c +1 -1
@@ -357,7 +357,7 @@struct link_socket_info *lsi =get_link_socket_info (c);struct options *o = &c->options; -int pmtu = c->c2.link_socket->mtu; +int pmtu = c->c2.link_sockets[0 ]->mtu;sa_family_t af = lsi->lsa->actual.dest.addr.sa.sa_family;int proto = lsi->proto;
src/openvpn/mtcp.c +34 -20
114 lines not on this page · raw message
src/openvpn/mudp.c +12 -7
@@ -185,7 +185,8 @@*/ struct multi_instance * -multi_get_create_instance_udp (struct multi_context *m,bool *floated) +multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct mroute_addr real = {0 };
@@ -256,7 +257,7 @@* connect-freq but not against connect-freq-initial */ reflect_filter_rate_limit_decrease (m->initial_rate_limiter); - mi =multi_create_instance (m, &real); + mi =multi_create_instance (m, &real, ls);if (mi) {hash_add_fast (hash, bucket, &mi->real, hv, mi);
@@ -317,7 +318,7 @@msg_set_prefix ("Connection Attempt" ); m->top.c2.to_link = m->hmac_reply; m->top.c2.to_link_addr = m->hmac_reply_dest; -process_outgoing_link (&m->top, m->top.c2.link_socket); +process_outgoing_link (&m->top, m->top.c2.link_sockets[0 ]); m->hmac_reply_dest =NULL ; } }
@@ -326,7 +327,7 @@* Process an I/O event. */ static void -multi_process_io_udp (struct multi_context *m) +multi_process_io_udp (struct multi_context *m,struct link_socket *sock) {const unsigned int status = m->top.c2.event_set_status;const unsigned int mpp_flags = m->top.c2.fast_io
@@ -380,10 +381,10 @@/* Incoming data on UDP port */ else if (status & SOCKET_READ) { -read_incoming_link (&m->top, m->top.c2.link_socket); +read_incoming_link (&m->top, sock);if (!IS_SIG (&m->top)) { -multi_process_incoming_link (m,NULL , mpp_flags); +multi_process_incoming_link (m,NULL , mpp_flags, sock); } }/* Incoming data on TUN device */
@@ -514,7 +515,11 @@else {/* process I/O */ -multi_process_io_udp (&multi); + +/* Since there's only one link_socket just use the first, in an upcoming +* patch this will be changed by using the link_socket returned by the +* event set */ +multi_process_io_udp (&multi, top->c2.link_sockets[0 ]);MULTI_CHECK_SIG (&multi); }
src/openvpn/mudp.h +4 -2
@@ -55,12 +55,14 @@* it. If no entry exists, this function handles its creation, and if * successful, returns the newly created instance. * -* @param m - The single multi_context structure. +* @param m - The single multi_context structure. +* @param ls - Listening socket where this instance is connecting to * * @return A pointer to a multi_instance if one already existed for the * packet's source address or if one was a newly created successfully. * NULL if one did not yet exist and a new one was not created. */ -struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated); +struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls);#endif /* ifndef MUDP_H */
src/openvpn/multi.c +14 -10
@@ -750,7 +750,8 @@* Create a client instance object for a newly connected client. */ struct multi_instance * -multi_create_instance (struct multi_context *m,const struct mroute_addr *real) +multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct multi_instance *mi;
@@ -773,7 +774,7 @@generate_prefix (mi); } -inherit_context_child (&mi->context, &m->top); +inherit_context_child (&mi->context, &m->top, ls);if (IS_SIG (&mi->context)) { goto err;
@@ -3124,7 +3125,8 @@ }void -multi_process_float (struct multi_context *m,struct multi_instance *mi) +multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls) {struct mroute_addr real = {0 };struct hash *hash = m->hash;
@@ -3180,8 +3182,8 @@ mi->context.c2.to_link_addr = &mi->context.c2.from;/* inherit parent link_socket and link_socket_info */ - mi->context.c2.link_socket = m->top.c2.link_socket; - mi->context.c2.link_socket_info->lsa->actual = m->top.c2.from; + mi->context.c2.link_sockets[0 ] = ls; + mi->context.c2.link_socket_infos[0 ]->lsa->actual = m->top.c2.from;tls_update_remote_addr (mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3329,7 +3331,8 @@* i.e. client -> server direction. */ bool -multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags) +multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance, +const unsigned int mpp_flags,struct link_socket *ls) {struct gc_arena gc =gc_new ();
@@ -3350,7 +3353,7 @@#ifdef MULTI_DEBUG_EVENT_LOOP printf ("TCP/UDP -> TUN [%d]\n" ,BLEN (&m->top.c2.buf));#endif -multi_set_pending (m,multi_get_create_instance_udp (m, &floated)); +multi_set_pending (m,multi_get_create_instance_udp (m, &floated, ls)); }else {
@@ -3391,7 +3394,7 @@/* nonzero length means that we have a valid, decrypted packed */ if (floated && c->c2.buf.len >0 ) { -multi_process_float (m, m->pending); +multi_process_float (m, m->pending, ls); }process_incoming_link_part2 (c, lsi, orig_buf);
@@ -3610,7 +3613,7 @@ }/* encrypt in instance context */ -process_incoming_tun (c); +process_incoming_tun (c, c->c2.link_sockets[0 ]);/* postprocess and set wakeup */ ret =multi_process_post (m, m->pending, mpp_flags);
@@ -3642,7 +3645,8 @@ { pip_flags |=PIP_MSSFIX ; } -process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf); +process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf, + item.instance->context.c2.link_sockets[0 ]);encrypt_sign (&item.instance->context, true);mbuf_free_buf (item.buffer);
src/openvpn/multi.h +9 -5
@@ -275,7 +275,8 @@void multi_top_free (struct multi_context *m); -struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real); +struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls);void multi_close_instance (struct multi_context *m,struct multi_instance *mi,bool shutdown);
@@ -289,7 +290,8 @@* existing peer. Updates multi_instance with new address, * updates hashtables in multi_context. */ -void multi_process_float (struct multi_context *m,struct multi_instance *mi); +void multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls);#define MPP_PRE_SELECT (1<<0)#define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -354,8 +356,10 @@* when using TCP transport. Otherwise NULL, as is * the case when using UDP transport. * @param mpp_flags - Fast I/O optimization flags. +* @param ls - Socket where the packet was received. */ -bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags); +bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls);/**
@@ -669,7 +673,7 @@#endif set_prefix (mi);vlan_process_outgoing_tun (m, mi); -process_outgoing_tun (&mi->context); +process_outgoing_tun (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
@@ -684,7 +688,7 @@ {bool ret = true;set_prefix (mi); -process_outgoing_link (&mi->context, mi->context.c2.link_socket); +process_outgoing_link (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
src/openvpn/openvpn.c +1 -1
@@ -91,7 +91,7 @@ }/* process the I/O which triggered select */ -process_io (c, c->c2.link_socket); +process_io (c, c->c2.link_sockets[0 ]);P2P_CHECK_SIG ();perf_pop ();
src/openvpn/openvpn.h +5 -4
@@ -154,7 +154,8 @@*/ struct context_1 { -struct link_socket_addr link_socket_addr; +int link_sockets_num; +struct link_socket_addr *link_socket_addrs;/**< Local and remote addresses on the * external network. */
@@ -233,11 +234,11 @@/* bitmask for event status. Check event.h for possible values */ unsigned int event_set_status; -struct link_socket *link_socket;/* socket used for TCP/UDP connection to remote */ +struct link_socket **link_sockets; +struct link_socket_info **link_socket_infos; +bool link_socket_owned; -/** This variable is used instead link_socket->info for P2MP UDP childs */ -struct link_socket_info *link_socket_info;const struct link_socket *accept_from;/* possibly do accept() on a parent link_socket */ struct link_socket_actual *to_link_addr;/* IP address of remote */
src/openvpn/ping.h +1 -1
@@ -63,7 +63,7 @@ && event_timeout_trigger(&c->c2.ping_rec_interval, &c->c2.timeval, (!c->options.ping_timer_remote - || link_socket_actual_defined(&c->c1.link_socket_addr.actual)) + || link_socket_actual_defined(&c->c1.link_socket_addrs[0].actual)) ? ETT_DEFAULT : 15)) {trigger_ping_timeout_signal (c);
src/openvpn/socket.c +22 -9
@@ -42,6 +42,21 @@#include "memdbg.h" +bool +sockets_read_residual (const struct context *c) +{ +int i; + +for (i =0 ; i < c->c1.link_sockets_num; i++) + { +if (c->c2.link_sockets[i]->stream_buf.residual_fully_formed) + { +return true; + } + } +return false; +} +/* * Convert sockflags/getaddr_flags into getaddr_flags */
@@ -1454,7 +1469,6 @@#ifdef TARGET_ANDROID protect_fd_nonlocal (sd, remote);#endif -set_nonblock (sd); status =connect (sd, remote,af_addr_size (remote->sa_family));if (status)
@@ -1851,9 +1865,9 @@ }void -link_socket_init_phase1 (struct context *c,int mode) +link_socket_init_phase1 (struct context *c,int sock_index,int mode) { -struct link_socket *sock = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[sock_index];struct options *o = &c->options;ASSERT (sock);
@@ -1879,19 +1893,20 @@ sock->socket_buffer_sizes.sndbuf = o->sndbuf; sock->sockflags = o->sockflags; +#if PORT_SHARE if (o->port_share_host && o->port_share_port) { sock->sockflags |=SF_PORT_SHARE ; }#endif + sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; - sock->info.lsa = &c->c1.link_socket_addr; + sock->info.lsa = &c->c1.link_socket_addrs[sock_index]; sock->info.bind_ipv6_only = o->ce.bind_ipv6_only; sock->info.ipchange_command = o->ipchange; sock->info.plugins = c->plugins;
@@ -2186,9 +2201,9 @@/* finalize socket initialization */ void -link_socket_init_phase2 (struct context *c) +link_socket_init_phase2 (struct context *c, +struct link_socket *sock) { -struct link_socket *sock = c->c2.link_socket;const struct frame *frame = &c->c2.frame;struct signal_info *sig_info = c->sig;
@@ -2234,7 +2249,6 @@ {create_socket (sock, sock->info.lsa->current_remote); } - }/* If socket has not already been created create it now */
@@ -2253,7 +2267,6 @@ addr_family_name(sock->info.lsa->bind_local->ai_family)); sock->info.af = sock->info.lsa->bind_local->ai_family; } -create_socket (sock, sock->info.lsa->bind_local); } }
src/openvpn/socket.h +12 -7
@@ -344,9 +344,13 @@/* * Initialize link_socket object. */ -void link_socket_init_phase1 (struct context *c,int mode); +void +link_socket_init_phase1 (struct context *c, +int sock_index, +int mode); -void link_socket_init_phase2 (struct context *c); +void link_socket_init_phase2 (struct context *c, +struct link_socket *sock);void do_preresolve (struct context *c);
@@ -1228,11 +1232,12 @@* Socket I/O wait functions */ -static inline bool -socket_read_residual (const struct link_socket *sock) -{ -return sock && sock->stream_buf.residual_fully_formed; -} +/* +* Extends the pre-existing read residual logic +* to all initialized sockets, ensuring the complete +* packet is read. +*/ +bool sockets_read_residual (const struct context *c);static inline event_t socket_event_handle (const struct link_socket *sock)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 12
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: Adapt socket handling to support listening on multiple sockets
In reply to a message not in the archivecron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/434?usp=email )
Change subject: Adapt socket handling to support listening on multiple sockets
......................................................................
Adapt socket handling to support listening on multiple sockets
Introduce internal changes preparing the server to handle multiple sockets concurrently for both TCP and UDP protocols. While no user-visible features are implemented yet, these modifications are essential for enabling future functionality such as listening on multiple ports.
Key changes are: converting link_socket from a single pointer to an array in various contexts, in order to be able to store multiple sockets at once.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30309.html
---
M src/openvpn/dco.c
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mss.c
M src/openvpn/mtcp.c
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/openvpn.c
M src/openvpn/openvpn.h
M src/openvpn/ping.h
M src/openvpn/socket.c
M src/openvpn/socket.h
16 files changed, 326 insertions(+), 183 deletions(-)
src/openvpn/dco.c +9 -9
@@ -478,11 +478,11 @@return 0 ; } -struct link_socket *ls = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[0 ]; -ASSERT (ls->info.connection_established); +ASSERT (sock->info.connection_established); -struct sockaddr *remoteaddr = &ls->info.lsa->actual.dest.addr.sa; +struct sockaddr *remoteaddr = &sock->info.lsa->actual.dest.addr.sa;struct tls_multi *multi = c->c2.tls_multi;#ifdef TARGET_FREEBSD /* In Linux in P2P mode the kernel automatically removes an existing peer
@@ -494,7 +494,7 @@ }#endif int ret =dco_new_peer (&c->c1.tuntap->dco, multi->peer_id, - c->c2.link_socket->sd,NULL , remoteaddr,NULL ,NULL ); + c->c2.link_sockets[0 ]->sd,NULL , remoteaddr,NULL ,NULL );if (ret <0 ) {return ret;
@@ -527,12 +527,12 @@#if ENABLE_IP_PKTINFO struct context *c = &mi->context; -if (!proto_is_udp (c->c2.link_socket->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) +if (!proto_is_udp (c->c2.link_sockets[0 ]->info.proto) || !(c->options.sockflags &SF_USE_IP_PKTINFO )) {return false; } -struct link_socket_actual *actual = &c->c2.link_socket_info->lsa->actual; +struct link_socket_actual *actual = &c->c2.link_socket_infos[0 ]->lsa->actual;switch (actual->dest.addr.sa.sa_family) {
@@ -577,7 +577,7 @@int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 }; -int sd = c->c2.link_socket->sd; +int sd = c->c2.link_sockets[0 ]->sd;if (c->mode ==CM_CHILD_TCP )
@@ -587,8 +587,8 @@ }else { -ASSERT (c->c2.link_socket_info->connection_established); - remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; +ASSERT (c->c2.link_socket_infos[0 ]->connection_established); + remoteaddr = &c->c2.link_socket_infos[0 ]->lsa->actual.dest.addr.sa; }/* In server mode we need to fetch the remote addresses from the push config */
src/openvpn/forward.c +29 -18
134 lines not on this page · raw message
src/openvpn/forward.h +14 -10
@@ -231,10 +231,12 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with the -* packet. +* @param c The context structure of the VPN tunnel associated with +* the packet. +* @param out_sock Socket that will be used to send out the packet. +* */ -void process_incoming_tun (struct context *c); +void process_incoming_tun (struct context *c,struct link_socket *out_sock);/**
@@ -246,10 +248,11 @@* * If an error occurs, it is logged and the packet is dropped. * -* @param c - The context structure of the VPN tunnel associated with -* the packet. +* @param c The context structure of the VPN tunnel associated +* with the packet. +* @param in_sock Socket where the packet was received. */ -void process_outgoing_tun (struct context *c); +void process_outgoing_tun (struct context *c,struct link_socket *in_sock);/**************************************************************************/
@@ -304,20 +307,21 @@#define PIPV6_ICMP_NOHOST_SERVER (1<<6) -void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf); +void process_ip_header (struct context *c,unsigned int flags,struct buffer *buf, +struct link_socket *sock);bool schedule_exit (struct context *c);static inline struct link_socket_info *get_link_socket_info (struct context *c) { -if (c->c2.link_socket_info) +if (c->c2.link_socket_infos) { -return c->c2.link_socket_info; +return c->c2.link_socket_infos[0 ]; }else { -return &c->c2.link_socket->info; +return &c->c2.link_sockets[0 ]->info; } }
src/openvpn/init.c +157 -78
428 lines not on this page · raw message
src/openvpn/init.h +2 -1
@@ -95,7 +95,8 @@bool do_deferred_options (struct context *c,const unsigned int found);void inherit_context_child (struct context *dest, -const struct context *src); +const struct context *src, +struct link_socket *ls);void inherit_context_top (struct context *dest,const struct context *src);
src/openvpn/mss.c +1 -1
@@ -357,7 +357,7 @@struct link_socket_info *lsi =get_link_socket_info (c);struct options *o = &c->options; -int pmtu = c->c2.link_socket->mtu; +int pmtu = c->c2.link_sockets[0 ]->mtu;sa_family_t af = lsi->lsa->actual.dest.addr.sa.sa_family;int proto = lsi->proto;
src/openvpn/mtcp.c +34 -20
114 lines not on this page · raw message
src/openvpn/mudp.c +12 -7
@@ -185,7 +185,8 @@*/ struct multi_instance * -multi_get_create_instance_udp (struct multi_context *m,bool *floated) +multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct mroute_addr real = {0 };
@@ -256,7 +257,7 @@* connect-freq but not against connect-freq-initial */ reflect_filter_rate_limit_decrease (m->initial_rate_limiter); - mi =multi_create_instance (m, &real); + mi =multi_create_instance (m, &real, ls);if (mi) {hash_add_fast (hash, bucket, &mi->real, hv, mi);
@@ -317,7 +318,7 @@msg_set_prefix ("Connection Attempt" ); m->top.c2.to_link = m->hmac_reply; m->top.c2.to_link_addr = m->hmac_reply_dest; -process_outgoing_link (&m->top, m->top.c2.link_socket); +process_outgoing_link (&m->top, m->top.c2.link_sockets[0 ]); m->hmac_reply_dest =NULL ; } }
@@ -326,7 +327,7 @@* Process an I/O event. */ static void -multi_process_io_udp (struct multi_context *m) +multi_process_io_udp (struct multi_context *m,struct link_socket *sock) {const unsigned int status = m->top.c2.event_set_status;const unsigned int mpp_flags = m->top.c2.fast_io
@@ -380,10 +381,10 @@/* Incoming data on UDP port */ else if (status & SOCKET_READ) { -read_incoming_link (&m->top, m->top.c2.link_socket); +read_incoming_link (&m->top, sock);if (!IS_SIG (&m->top)) { -multi_process_incoming_link (m,NULL , mpp_flags); +multi_process_incoming_link (m,NULL , mpp_flags, sock); } }/* Incoming data on TUN device */
@@ -514,7 +515,11 @@else {/* process I/O */ -multi_process_io_udp (&multi); + +/* Since there's only one link_socket just use the first, in an upcoming +* patch this will be changed by using the link_socket returned by the +* event set */ +multi_process_io_udp (&multi, top->c2.link_sockets[0 ]);MULTI_CHECK_SIG (&multi); }
src/openvpn/mudp.h +4 -2
@@ -55,12 +55,14 @@* it. If no entry exists, this function handles its creation, and if * successful, returns the newly created instance. * -* @param m - The single multi_context structure. +* @param m - The single multi_context structure. +* @param ls - Listening socket where this instance is connecting to * * @return A pointer to a multi_instance if one already existed for the * packet's source address or if one was a newly created successfully. * NULL if one did not yet exist and a new one was not created. */ -struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated); +struct multi_instance *multi_get_create_instance_udp (struct multi_context *m,bool *floated, +struct link_socket *ls);#endif /* ifndef MUDP_H */
src/openvpn/multi.c +14 -10
@@ -750,7 +750,8 @@* Create a client instance object for a newly connected client. */ struct multi_instance * -multi_create_instance (struct multi_context *m,const struct mroute_addr *real) +multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls) {struct gc_arena gc =gc_new ();struct multi_instance *mi;
@@ -773,7 +774,7 @@generate_prefix (mi); } -inherit_context_child (&mi->context, &m->top); +inherit_context_child (&mi->context, &m->top, ls);if (IS_SIG (&mi->context)) { goto err;
@@ -3124,7 +3125,8 @@ }void -multi_process_float (struct multi_context *m,struct multi_instance *mi) +multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls) {struct mroute_addr real = {0 };struct hash *hash = m->hash;
@@ -3180,8 +3182,8 @@ mi->context.c2.to_link_addr = &mi->context.c2.from;/* inherit parent link_socket and link_socket_info */ - mi->context.c2.link_socket = m->top.c2.link_socket; - mi->context.c2.link_socket_info->lsa->actual = m->top.c2.from; + mi->context.c2.link_sockets[0 ] = ls; + mi->context.c2.link_socket_infos[0 ]->lsa->actual = m->top.c2.from;tls_update_remote_addr (mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3329,7 +3331,8 @@* i.e. client -> server direction. */ bool -multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags) +multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance, +const unsigned int mpp_flags,struct link_socket *ls) {struct gc_arena gc =gc_new ();
@@ -3350,7 +3353,7 @@#ifdef MULTI_DEBUG_EVENT_LOOP printf ("TCP/UDP -> TUN [%d]\n" ,BLEN (&m->top.c2.buf));#endif -multi_set_pending (m,multi_get_create_instance_udp (m, &floated)); +multi_set_pending (m,multi_get_create_instance_udp (m, &floated, ls)); }else {
@@ -3391,7 +3394,7 @@/* nonzero length means that we have a valid, decrypted packed */ if (floated && c->c2.buf.len >0 ) { -multi_process_float (m, m->pending); +multi_process_float (m, m->pending, ls); }process_incoming_link_part2 (c, lsi, orig_buf);
@@ -3610,7 +3613,7 @@ }/* encrypt in instance context */ -process_incoming_tun (c); +process_incoming_tun (c, c->c2.link_sockets[0 ]);/* postprocess and set wakeup */ ret =multi_process_post (m, m->pending, mpp_flags);
@@ -3642,7 +3645,8 @@ { pip_flags |=PIP_MSSFIX ; } -process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf); +process_ip_header (&item.instance->context, pip_flags, &item.instance->context.c2.buf, + item.instance->context.c2.link_sockets[0 ]);encrypt_sign (&item.instance->context, true);mbuf_free_buf (item.buffer);
src/openvpn/multi.h +9 -5
@@ -275,7 +275,8 @@void multi_top_free (struct multi_context *m); -struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real); +struct multi_instance *multi_create_instance (struct multi_context *m,const struct mroute_addr *real, +struct link_socket *ls);void multi_close_instance (struct multi_context *m,struct multi_instance *mi,bool shutdown);
@@ -289,7 +290,8 @@* existing peer. Updates multi_instance with new address, * updates hashtables in multi_context. */ -void multi_process_float (struct multi_context *m,struct multi_instance *mi); +void multi_process_float (struct multi_context *m,struct multi_instance *mi, +struct link_socket *ls);#define MPP_PRE_SELECT (1<<0)#define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -354,8 +356,10 @@* when using TCP transport. Otherwise NULL, as is * the case when using UDP transport. * @param mpp_flags - Fast I/O optimization flags. +* @param ls - Socket where the packet was received. */ -bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags); +bool multi_process_incoming_link (struct multi_context *m,struct multi_instance *instance,const unsigned int mpp_flags, +struct link_socket *ls);/**
@@ -669,7 +673,7 @@#endif set_prefix (mi);vlan_process_outgoing_tun (m, mi); -process_outgoing_tun (&mi->context); +process_outgoing_tun (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
@@ -684,7 +688,7 @@ {bool ret = true;set_prefix (mi); -process_outgoing_link (&mi->context, mi->context.c2.link_socket); +process_outgoing_link (&mi->context, mi->context.c2.link_sockets[0 ]); ret =multi_process_post (m, mi, mpp_flags);clear_prefix ();return ret;
src/openvpn/openvpn.c +1 -1
@@ -91,7 +91,7 @@ }/* process the I/O which triggered select */ -process_io (c, c->c2.link_socket); +process_io (c, c->c2.link_sockets[0 ]);P2P_CHECK_SIG ();perf_pop ();
src/openvpn/openvpn.h +5 -4
@@ -154,7 +154,8 @@*/ struct context_1 { -struct link_socket_addr link_socket_addr; +int link_sockets_num; +struct link_socket_addr *link_socket_addrs;/**< Local and remote addresses on the * external network. */
@@ -233,11 +234,11 @@/* bitmask for event status. Check event.h for possible values */ unsigned int event_set_status; -struct link_socket *link_socket;/* socket used for TCP/UDP connection to remote */ +struct link_socket **link_sockets; +struct link_socket_info **link_socket_infos; +bool link_socket_owned; -/** This variable is used instead link_socket->info for P2MP UDP childs */ -struct link_socket_info *link_socket_info;const struct link_socket *accept_from;/* possibly do accept() on a parent link_socket */ struct link_socket_actual *to_link_addr;/* IP address of remote */
src/openvpn/ping.h +1 -1
@@ -63,7 +63,7 @@ && event_timeout_trigger(&c->c2.ping_rec_interval, &c->c2.timeval, (!c->options.ping_timer_remote - || link_socket_actual_defined(&c->c1.link_socket_addr.actual)) + || link_socket_actual_defined(&c->c1.link_socket_addrs[0].actual)) ? ETT_DEFAULT : 15)) {trigger_ping_timeout_signal (c);
src/openvpn/socket.c +22 -9
@@ -42,6 +42,21 @@#include "memdbg.h" +bool +sockets_read_residual (const struct context *c) +{ +int i; + +for (i =0 ; i < c->c1.link_sockets_num; i++) + { +if (c->c2.link_sockets[i]->stream_buf.residual_fully_formed) + { +return true; + } + } +return false; +} +/* * Convert sockflags/getaddr_flags into getaddr_flags */
@@ -1454,7 +1469,6 @@#ifdef TARGET_ANDROID protect_fd_nonlocal (sd, remote);#endif -set_nonblock (sd); status =connect (sd, remote,af_addr_size (remote->sa_family));if (status)
@@ -1851,9 +1865,9 @@ }void -link_socket_init_phase1 (struct context *c,int mode) +link_socket_init_phase1 (struct context *c,int sock_index,int mode) { -struct link_socket *sock = c->c2.link_socket; +struct link_socket *sock = c->c2.link_sockets[sock_index];struct options *o = &c->options;ASSERT (sock);
@@ -1879,19 +1893,20 @@ sock->socket_buffer_sizes.sndbuf = o->sndbuf; sock->sockflags = o->sockflags; +#if PORT_SHARE if (o->port_share_host && o->port_share_port) { sock->sockflags |=SF_PORT_SHARE ; }#endif + sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; - sock->info.lsa = &c->c1.link_socket_addr; + sock->info.lsa = &c->c1.link_socket_addrs[sock_index]; sock->info.bind_ipv6_only = o->ce.bind_ipv6_only; sock->info.ipchange_command = o->ipchange; sock->info.plugins = c->plugins;
@@ -2186,9 +2201,9 @@/* finalize socket initialization */ void -link_socket_init_phase2 (struct context *c) +link_socket_init_phase2 (struct context *c, +struct link_socket *sock) { -struct link_socket *sock = c->c2.link_socket;const struct frame *frame = &c->c2.frame;struct signal_info *sig_info = c->sig;
@@ -2234,7 +2249,6 @@ {create_socket (sock, sock->info.lsa->current_remote); } - }/* If socket has not already been created create it now */
@@ -2253,7 +2267,6 @@ addr_family_name(sock->info.lsa->bind_local->ai_family)); sock->info.af = sock->info.lsa->bind_local->ai_family; } -create_socket (sock, sock->info.lsa->bind_local); } }
src/openvpn/socket.h +12 -7
@@ -344,9 +344,13 @@/* * Initialize link_socket object. */ -void link_socket_init_phase1 (struct context *c,int mode); +void +link_socket_init_phase1 (struct context *c, +int sock_index, +int mode); -void link_socket_init_phase2 (struct context *c); +void link_socket_init_phase2 (struct context *c, +struct link_socket *sock);void do_preresolve (struct context *c);
@@ -1228,11 +1232,12 @@* Socket I/O wait functions */ -static inline bool -socket_read_residual (const struct link_socket *sock) -{ -return sock && sock->stream_buf.residual_fully_formed; -} +/* +* Extends the pre-existing read residual logic +* to all initialized sockets, ensuring the complete +* packet is read. +*/ +bool sockets_read_residual (const struct context *c);static inline event_t socket_event_handle (const struct link_socket *sock)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0a889e800f0b36aed770ee36e31afeec5df6084
Gerrit-Change-Number: 434
Gerrit-PatchSet: 12
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged